From ab60433626ff2fad207c9bea5b3ac8c11f273db7 Mon Sep 17 00:00:00 2001 From: Mike West Date: Tue, 2 Mar 2021 08:01:54 -0800 Subject: [PATCH] WPT: `Sec-Fetch-*` headers aren't accessible in service workers. As requested in https://github.com/whatwg/fetch/pull/993. Change-Id: Ie6096154ad9f6af73e2c26e0bb0c8f72a2a7a99a --- .../serviceworker-accessors-frame.html | 3 ++ .../resources/serviceworker-accessors.sw.js | 14 ++++++ .../serviceworker-accessors.https.sub.html | 45 +++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 fetch/metadata/resources/serviceworker-accessors-frame.html create mode 100644 fetch/metadata/resources/serviceworker-accessors.sw.js create mode 100644 fetch/metadata/serviceworker-accessors.https.sub.html diff --git a/fetch/metadata/resources/serviceworker-accessors-frame.html b/fetch/metadata/resources/serviceworker-accessors-frame.html new file mode 100644 index 000000000000000..98798025005497f --- /dev/null +++ b/fetch/metadata/resources/serviceworker-accessors-frame.html @@ -0,0 +1,3 @@ + + +Page Title diff --git a/fetch/metadata/resources/serviceworker-accessors.sw.js b/fetch/metadata/resources/serviceworker-accessors.sw.js new file mode 100644 index 000000000000000..36c55a778600f48 --- /dev/null +++ b/fetch/metadata/resources/serviceworker-accessors.sw.js @@ -0,0 +1,14 @@ +addEventListener("fetch", event => { + event.waitUntil(async function () { + if (!event.clientId) return; + const client = await clients.get(event.clientId); + if (!client) return; + + client.postMessage({ + "dest": event.request.headers.get("sec-fetch-dest"), + "mode": event.request.headers.get("sec-fetch-mode"), + "site": event.request.headers.get("sec-fetch-site"), + "user": event.request.headers.get("sec-fetch-user") + }); + }()); +}); diff --git a/fetch/metadata/serviceworker-accessors.https.sub.html b/fetch/metadata/serviceworker-accessors.https.sub.html new file mode 100644 index 000000000000000..6788135f863f109 --- /dev/null +++ b/fetch/metadata/serviceworker-accessors.https.sub.html @@ -0,0 +1,45 @@ + + + + + + + + +