blob: 7863af70d7835e573356cc02e6bdc29f626acc5a [file] [log] [blame]
// This is the (shared or dedicated) worker file for the
// worker-interception-redirect test. It should be served by the corresponding
// .py file instead of being served directly.
//
// This file is served from both resources/*webworker.py and
// resources/scope2/*webworker.py, hence some of the complexity
// below about paths.
const resources_url = new URL("/service-workers/service-worker/resources/",
self.location);
// This greeting text is meant to be injected by the Python script that serves
// this file, to indicate how the script was served (from network or from
// service worker).
//
// We can't just use a sub pipe and name this file .sub.js since we want
// to serve the file from multiple URLs (see above).
let greeting = '%GREETING_TEXT%';
if (!greeting)
greeting = 'the shared worker script was served from network';
self.onconnect = async function(e) {
const port = e.ports[0];
port.start();
port.postMessage(greeting);
const fetch_url = new URL('simple.txt', resources_url);
const response = await fetch(fetch_url);
const text = await response.text();
port.postMessage('fetch(): ' + text);
};