Skip to content
Development

Run OneSignal and a PWA service worker together

OneSignal push and a WordPress PWA both want a service worker. Learn how scope works, how to give each its own, and how to test that push still works.

By WP24×7 engineers5 min readPublished June 18, 2021Updated November 29, 2026

At a glance

OneSignal web push and a WordPress progressive web app both depend on a service worker, and a page can have only one per scope, so when both claim the whole site, one loses. Give OneSignal its own scope, or combine the two scripts deliberately. This developer guide shows how to see registrations, set separate scopes, test push and avoid common failures.

Updated November 29, 2026

  • For developers running OneSignal push and a PWA on one WordPress site
  • Cause one service worker per scope; the latest registration wins
  • Recommended separate scopes, PWA at root, OneSignal on a sub-path
  • Alternative one worker importing the other with importScripts
  • Needs HTTPS, except localhost in development
  • Before changing back up, test on staging, check OneSignal's current docs
  • Help WordPress and plugin development

A progressive web app (PWA) and OneSignal web push both depend on a service worker, a script the browser runs in the background. A page can have only one service worker per scope, so when both try to claim the whole site, one loses. The fix is to give OneSignal its own scope, or to combine the two scripts deliberately.

This is a developer-level change. Back up the site, test on staging, and treat code as a child-theme or small-plugin job. The OneSignal plugin and SDK change often, so check OneSignal's current documentation for exact file names and options before you copy any snippet.

Why do they conflict?

A service worker is registered with a scope: the part of the site it can control. A worker at /sw.js with the default scope controls everything under /. If the PWA registers that, and OneSignal also wants the root scope, the browser keeps one registration per scope. The most recent registration replaces the earlier one, so one feature silently stops working: the PWA loses offline caching, or push subscriptions fail with a service worker error.

Symptoms: the browser console shows service worker registration errors, the OneSignal prompt never appears, a subscription is created and then dropped, or Application, Service Workers in Chrome DevTools shows a different script than you expected.

How do I see which workers are registered?

  1. Open your site in Chrome, then DevTools, then the Application tab.
  2. Choose Service Workers. Note each scope and script URL. Tick Show all if you have several.
  3. Use Unregister while experimenting, so you test from a clean state.

What are the two main approaches?

Separate scopesOne worker imports the other
RecommendedYesOnly if you must share the root scope
MaintenanceEach product updates on its ownYou maintain the combined file
DebuggingSimplerHarder
Two service workers, each with its own scope

Approach 1: separate scopes (recommended). Let the PWA keep the root scope and move OneSignal's worker to a sub-path that is not covered by it. OneSignal's current web SDK lets you set the worker path and scope in its init options, and by default it uses a dedicated path. When you use the OneSignal WordPress plugin, the plugin manages this for you, so first check its settings for options about the service worker.

If you initialise OneSignal yourself, the pattern looks like this. Replace YOUR-APP-ID, and place the OneSignal worker file, downloaded from OneSignal's setup documentation, on your own domain at the path given:

<script src="https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js" defer></script>
<script>
	window.OneSignalDeferred = window.OneSignalDeferred || [];
	OneSignalDeferred.push(async function (OneSignal) {
		await OneSignal.init({
			appId: "YOUR-APP-ID",
			serviceWorkerPath: "push/onesignal/OneSignalSDKWorker.js",
			serviceWorkerParam: { scope: "/push/onesignal/" }
		});
	});
</script>

If the OneSignal plugin also initialises the SDK, you must turn that off, as the old approach on this blog did, so that only one init runs. Two inits cause duplicate prompts and errors.

To print the script from WordPress without editing theme templates, use a small plugin:

add_action( 'wp_enqueue_scripts', function () {
	wp_enqueue_script(
		'onesignal-sdk',
		'https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js',
		array(),
		null,
		array( 'strategy' => 'defer', 'in_footer' => false )
	);

	wp_add_inline_script(
		'onesignal-sdk',
		'window.OneSignalDeferred = window.OneSignalDeferred || [];
		OneSignalDeferred.push(async function (OneSignal) {
			await OneSignal.init({
				appId: ' . wp_json_encode( 'YOUR-APP-ID' ) . ',
				serviceWorkerPath: "push/onesignal/OneSignalSDKWorker.js",
				serviceWorkerParam: { scope: "/push/onesignal/" }
			});
		});',
		'after'
	);
} );

wp_json_encode prints the ID as a safely quoted JavaScript string. The strategy argument needs WordPress 6.3 or later.

Because of the sub-scope, the OneSignal worker controls push events, which do not depend on scope for delivery, while your PWA worker still controls page caching.

Approach 2: one worker that imports the other. If you must use the root scope for both, your PWA's worker file can load OneSignal's worker as its first line, using a path from OneSignal's documentation:

importScripts("https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.sw.js");

You then register only your worker and point OneSignal to it with its serviceWorkerPath option. This works, but you must now maintain the combined file and recheck it whenever either product updates. It is also harder to debug, so prefer separate scopes.

Where must the files live?

A service worker file must be served from your own domain, with a JavaScript content type, and its path decides the maximum scope it can claim, unless the server sends a Service-Worker-Allowed header. That is why a worker uploaded to /wp-content/plugins/... can only control URLs under that folder. Putting the OneSignal worker in a sub-folder at the site root gives it a clean, predictable path.

How do I test push after the change?

  1. Unregister

    all workers for the site, clear site data, then reload the page.

  2. Confirm

    in Application, Service Workers that both scopes are registered and active.

  3. Click

    the OneSignal prompt (see changing the prompt text) and allow notifications.

  4. Send

    a test message to your own subscription from OneSignal's dashboard.

  5. Confirm

    it arrives with the tab open and closed. Check that offline behaviour from the PWA still works.

What commonly goes wrong?

ProblemWhat to do
Caching plugins minify, combine or delay JavaScriptExclude the OneSignal scripts from optimisation
Old workers cached by browsersUsers need a refresh or two before a new worker takes over
Mixed content or no HTTPSServe everything over HTTPS
Manifest warningSeparate from push; see adding a short_name to the manifest
Plugin versionsFeatures have moved or been retired; check what your version still provides

If you want this done and tested across browsers, our WordPress development team and plugin developers can do it.

Want this built and tested across browsers?

Our developers can do it. Post a project and a person will quote in writing.

FAQ

Questions people ask

13 answers. Can't find yours? Ask an engineer.

Why does OneSignal stop working after I add a PWA plugin?

Two service workers cannot control the same scope. If the PWA plugin registers one for the whole site, OneSignal's worker may be replaced or never registered, so push subscriptions fail.

Link to this answer
Can OneSignal and a PWA share one service worker?

Yes, by importing OneSignal's worker script into your own with importScripts, but that is more fragile than separate scopes, so prefer separate scopes first.

Link to this answer
Do I need HTTPS?

Yes. Service workers and push notifications need a secure origin, apart from localhost during development.

Link to this answer
Why does OneSignal stop working after I add a PWA plugin?

Two service workers cannot control the same scope. If the PWA plugin registers one for the whole site, OneSignal's worker may be replaced or never registered, so push subscriptions fail.

Link to this answer
How do I see which service workers are registered?

In Chrome, open DevTools, Application, Service Workers and note each scope and script URL. In the console, navigator.serviceWorker.getRegistrations lists scopes. Use Unregister while experimenting to test from a clean state.

Link to this answer
What are the symptoms of a conflict?

Registration errors in the console, a OneSignal prompt that never appears, a subscription created then dropped, or a different script listed in DevTools than you expected.

Link to this answer
Which approach should I prefer?

Separate scopes. Let the PWA keep the root scope and move OneSignal's worker to a sub-path. Importing one worker into the other works but you must maintain the combined file and recheck it whenever either product updates.

Link to this answer
Why does the worker file location matter?

A worker must be served from your own domain with a JavaScript content type, and its path decides the maximum scope unless the server sends a Service-Worker-Allowed header. A worker under a plugin folder can only control URLs under that folder.

Link to this answer
Can I let the OneSignal plugin and my own init both run?

No. Turn off the plugin's init if you initialise OneSignal yourself, so only one init runs. Two inits cause duplicate prompts and errors.

Link to this answer
Do I need HTTPS?

Yes. Service workers and push notifications need a secure origin, apart from localhost during development.

Link to this answer
How do I test push after the change?

Unregister all workers and clear site data, reload, confirm both scopes are active, allow notifications, send a test message from OneSignal's dashboard, confirm it arrives with the tab open and closed and check PWA offline behaviour.

Link to this answer
What commonly breaks it?

Caching plugins that minify, combine or delay the scripts, old workers cached by browsers that need a refresh or two, mixed content, and plugin versions that have moved or retired features.

Link to this answer
Does a manifest warning stop push notifications?

No. Manifest and notification permissions are separate, so a manifest warning does not stop push.

Link to this answer

Keep reading

Want an engineer on it?

Tell us what is wrong in plain words. A person reads it, today.