Skip to content

WorkerGlobalScope.importScripts should be overwritten #2521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wentwrong opened this issue Dec 23, 2020 · 0 comments · Fixed by #2649
Closed

WorkerGlobalScope.importScripts should be overwritten #2521

wentwrong opened this issue Dec 23, 2020 · 0 comments · Fixed by #2649

Comments

@wentwrong
Copy link
Contributor

The WorkerGlobalScope.importScripts() method is being used to import scripts into worker global scope. We should handle URLs passed to it, because otherwise imported resources may not be processed by HH.

Example in which the imported script should be processed, but it doesn't:

require('http')
    .createServer((req, res) => {
        if (req.url === '/') {
            res.writeHead(200, { 'content-type': 'text/html' });
            res.end(`
                <!DOCTYPE html>
                <head>
                    <link rel="shortcut icon" href="#" />
                </head>
                <body>
                    <script>
                        navigator.serviceWorker.register('sw.js');
                    </script>
                </body>
            `);
        } else if (req.url === '/sw.js') {
            res.writeHead(200, { 'content-type': 'application/javascript' });
            res.end(`
                self.addEventListener('fetch', function(event) {
                    console.log('fetch event in sw.js with url', event.request.url);
                });

                importScripts('https://wentwrong.github.io/sw-fetch/one-more-service-worker.js');
            `);
        } else
            res.destroy();
    })
    .listen(2020, () => console.log('http://localhost:2020'));

This bug was found during analysis of the Health-Monitor run issues on the twitter.com website.

@LavrovArtem LavrovArtem self-assigned this Mar 12, 2021
LavrovArtem added a commit to LavrovArtem/testcafe-hammerhead that referenced this issue Jun 9, 2021
miherlosev pushed a commit that referenced this issue Jun 10, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
) (#2649)

* fix `WorkerGlobalScope.importScripts should be overwritten` (close #2521)

* review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment