npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cross-domain-worker

v0.1.2

Published

Cross-Domain Worker ===================

Readme

Cross-Domain Worker

Correctly handles cross-domain (aka cross-origin) workers with Webpack async chunks.

Usage

$ npm install cross-domain-worker
# or
$ yarn add cross-domain-worker

Prerequisite:

In order to properly work your Worker's webpack.config.js should have target: 'webworker' like this:

module.exports = {
    target: 'webworker',
    devtool: 'source-map', // suggested for better sourcemaps support
    // ... rest of the stuff
};

In the main thread:

import { createWorker } from 'cross-domain-worker';

const worker = await createWorker("http://localhost:4000/worker.js");
// or
createWorker("http://localhost:4000/test/main.js").then(worker => { /* your code */ });

In the worker:

import { setPath } from 'cross-domain-worker';

self.onmessage = async (ev) => {
    if (setPath(ev)) return;

    // your code
    
    // will work as expected, e.g. will be downloaded from proper URL, and will create a separate chunk as expected
    await import('./dynamic-module');
};

Webpack Asset Modules

Webpack Asset Modules are fully supported.

You can use standard webpack.config.js syntax:

module.exports = {
    // ... rest of the stuff
    module: {
        rules: [
            {
                test: /\.(png|jpe?g|gif)$/i,
                type: 'asset', // or 'asset/inline' or 'asset/resource'
            },
        ],
    }
};

And then load them as usual:

const {default: image} = await import('./path-to/image.png');
const res = await fetch(image);
const blob = await res.blob();

More reading

Package started as solution for https://github.com/webpack/webpack/issues/16696. During exploration library-worty technique has emereged. Read the ticket for extra information on cross-origin Worker limitations.

Consider situation when you have main script in https://a.com and request worker from https://b.com.

Without the library you will get errors like Uncaught DOMException: Failed to construct 'Worker': Script at 'http://b.com/worker.js' cannot be accessed from origin 'https://a.com'..

Even setting proper header Content-Security-Policy: worker-src https://b.com will not help.

This can be fixed by using Blob technique:

const blob = new Blob([`importScripts('https://b.com/worker.js')`], {'type': 'application/javascript'});
const worker = new Worker(URL.createObjectURL(blob));

But in this case if you are using dynamic import() in the worker you will get error Uncaught (in promise) DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'blob:http://a.com/script.js' failed to load. — note that browser will try to load chunk from https://a.com (host) and not https://b.com (worker).

This library conveniently fixes both issues, so that "things just work".

How to demo

npm install
npm start

Open http://localhost:3000 and check console.

Similar packages

All these packages use same Blob technique to overcome cross-origin Worker limitations, but they do not fix the Webpack paths of chunks:

  • https://www.npmjs.com/package/remote-web-worker
  • https://www.npmjs.com/package/co-web-worker
  • https://www.npmjs.com/package/cross-domain-worker-url
  • https://www.npmjs.com/package/crossoriginworker