-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UA-CH] Add userAgentData worker support
This implements PR #80 [1] and exposes userAgentData in workers. [1] WICG/ua-client-hints#80 Change-Id: I1de6067ab6c00855d7bf820e9646eb4e5a8c5fdb
- Loading branch information
1 parent
4c698c2
commit 53467ca
Showing
4 changed files
with
66 additions
and
8 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
...ppapis/system-state-and-capabilities/the-navigator-object/navigator_user_agent.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<title> WorkerNavigator.userAgentData </title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<div id=log></div> | ||
<script> | ||
|
||
promise_test(async () => { | ||
const e = await new Promise((resolve, reject) => { | ||
const worker = new Worker("./support/WorkerNavigator.js"); | ||
worker.onmessage = resolve; | ||
}); | ||
|
||
assert_equals(e.data.uaList, undefined); | ||
assert_equals(e.data.mobile, undefined); | ||
assert_equals(e.data.getHighEntropyValues, undefined); | ||
}, "Test userAgentData in workers"); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!DOCTYPE html> | ||
<title> WorkerNavigator.userAgentData </title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<div id=log></div> | ||
<script> | ||
|
||
promise_test(async () => { | ||
const e = await new Promise((resolve, reject) => { | ||
const worker = new Worker("./support/WorkerNavigator.js"); | ||
worker.onmessage = resolve; | ||
}); | ||
|
||
assert_equals(e.data.uaList.length, navigator.userAgentData.uaList.length); | ||
for (let i = 0; i < e.data.uaList.length; ++i) { | ||
const workerUA = e.data.uaList[i]; | ||
const windowUA = navigator.userAgentData.uaList[i]; | ||
assert_equals(workerUA.brand, windowUA.brand); | ||
assert_equals(workerUA.version, windowUA.version); | ||
} | ||
assert_equals(e.data.mobile, navigator.userAgentData.mobile); | ||
const highEntropyValues = await navigator.userAgentData.getHighEntropyValues(["platform", "platformVersion", "architecture", "model", "uaFullVersion"]); | ||
assert_equals(e.data.model, highEntropyValues.model); | ||
assert_equals(e.data.platform, highEntropyValues.platform); | ||
assert_equals(e.data.platformVersion, highEntropyValues.platformVersion); | ||
assert_equals(e.data.architecture, highEntropyValues.architecture); | ||
assert_equals(e.data.uaFullVersion, highEntropyValues.uaFullVersion); | ||
}, "Test userAgentData in workers"); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
var obj = new Object(); | ||
obj.appName = navigator.appName; | ||
obj.appVersion = navigator.appVersion; | ||
obj.platform = navigator.platform; | ||
obj.userAgent = navigator.userAgent; | ||
obj.onLine = navigator.onLine; | ||
(async () => { | ||
var obj = new Object(); | ||
obj.appName = navigator.appName; | ||
obj.appVersion = navigator.appVersion; | ||
obj.platform = navigator.platform; | ||
obj.userAgent = navigator.userAgent; | ||
obj.onLine = navigator.onLine; | ||
if (navigator.userAgentData) { | ||
obj.uaList = navigator.userAgentData.uaList; | ||
obj.mobile = navigator.userAgentData.mobile; | ||
const highEntropyValues = await navigator.userAgentData.getHighEntropyValues(["platform", "platformVersion", "architecture", "model", "uaFullVersion"]); | ||
|
||
postMessage(obj); | ||
obj.platform = highEntropyValues.platform; | ||
obj.platformVersion = highEntropyValues.platformVersion; | ||
obj.architecture = highEntropyValues.architecture; | ||
obj.model = highEntropyValues.model; | ||
obj.uaFullVersion = highEntropyValues.uaFullVersion; | ||
} | ||
postMessage(obj); | ||
})(); |