-
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 Bug: 1062192 Change-Id: I1de6067ab6c00855d7bf820e9646eb4e5a8c5fdb
- Loading branch information
1 parent
74e1fe4
commit a6b01bb
Showing
4 changed files
with
68 additions
and
9 deletions.
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
...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,17 @@ | ||
<!DOCTYPE html> | ||
<title> WorkerNavigator.userAgentData </title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<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 that userAgentData is not available in workers in non-secure contexts"); | ||
</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> | ||
<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); | ||
assert_equals(e.data.NavigatorUADataExposed, true); | ||
}, "Test that userAgentData is available in workers in secure contexts"); | ||
</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; | ||
|
||
postMessage(obj); | ||
(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"]); | ||
obj.platform = highEntropyValues.platform; | ||
obj.platformVersion = highEntropyValues.platformVersion; | ||
obj.architecture = highEntropyValues.architecture; | ||
obj.model = highEntropyValues.model; | ||
obj.uaFullVersion = highEntropyValues.uaFullVersion; | ||
obj.NavigatorUADataExposed = (typeof self.NavigatorUAData != "undefined"); | ||
} | ||
postMessage(obj); | ||
})(); |