Trouble using any plugin relying on web workers

Hi guys !

I am an happy (and mainly silent :sweat_smile:) user of roots toolkit to help me maintaining multiple WP installations. I have started by converting existing WP install to bedrock, then I am now using trellis to build my servers and deploy easily at each iteration.

The journey since the start (mid 2019) is really nice and I really enjoy all the benefit plus the community.

But I encounter one main issue theise days around a few plugins that I want to install, that are relying on web workers I think ?:

both seems to rely on a manifest.json file and seems pretty difficult to make it work with bedrock folder organization.

Currently the issue I have with onesignal:

ServiceWorkerManager.js:363 [Service Worker Installation] Installing service worker failed SecurityError: Failed to register a ServiceWorker: The origin of the provided scope ('https://test.distances.plussdk_files') does not match the current origin ('https://test.distances.plus').

Here is for example an issue reported on SuperPWA: https://wordpress.org/support/topic/not-works-for-my-site/

Do you guys have found a way to deal with such issues ? Any option ? I am asking myself if using Sage theme can help me on this journey ?

Thanks for your reading !

The immediate issue you’re facing doesn’t appear to be related to bedrock. 'https://test.distances.plussdk_files' looks like it’s missing a / , and should be 'https://test.distances.plus/sdk_files', so the origins match. You’ll have to check if that’s coming from something you configured, or a bug in the plugin itself.

…

As for your broader question about using service worker plugins with Bedrock, your success will depend on what the plugin worker is handling and how it’s written. The issue comes from the fact that a service worker can only manage requests within its scope, and the maximum scope it can have is its own URL path. (So, example.com/wp/sw.js can manage a request for example.com/wp/something, but not for example.com/something).

If the worker is trying to manage requests across the entire site, it would probably work as long as the plugin is well-written, handles subdirectory installs, doesn’t assume content and uploads are in the default directories… and so forth.

If the service worker file is being dynamically generated (instead of saving a static file to the filesystem), the plugin should probably mimic how WP generates robots.txt. WP handles robots.txt through the template loader, so preferably the plugin would use the template_include or template_redirect hooks to produce the service worker file.

Failing that, you could manually upload the service worker .js file in Bedrock’s web/ directory. The plugin may or may not make that easy :stuck_out_tongue_winking_eye:

Using Sage wouldn’t matter one way or another.

Hello,

Thanks for your complete help on the subject. It’s not very easy for me as it deal with area I am not very comfortable with :sweat_smile: (service workers, and so !).

I will try to play with uploading the js file directly under the web/ subdirectory (it doesn’t seems to be correctly handled by the mentioned plugins).

I will give you some update later :wink:

Cheers and good luck! It’s definitely a complex topic. Google’s docs about service workers are very good if you need a reference.

For the tiny bit of work I’ve done using service workers on WP, I did it the same way, uploading a js file I wrote myself. It’s just much simpler (assuming you’re comfortable writing the code) and less likely to break.

Regarding OneSignal I have found a more simple solution, follow the ‘classic’ procedure without WordPress, it’s as easy as dropping some js file in web/ folder :smiley:

Sometimes no plugin is better :wink:

This topic was automatically closed after 42 days. New replies are no longer allowed.