Skip to content
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

Workbox logs errors to console in Site Editor #1127

Open
westonruter opened this issue Apr 5, 2024 · 0 comments
Open

Workbox logs errors to console in Site Editor #1127

westonruter opened this issue Apr 5, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@westonruter
Copy link
Collaborator

As reported in a support topic by @RavanH, when the PWA plugin is active the browser console has an error appearing in the Site Editor:

Uncaught (in promise) TypeError: Failed to register a ServiceWorker: The URL protocol of the scope (':') is not supported.
    at a.es (Workbox.js:486:55)
    at a.register (Workbox.js:299:41)

This is coming from the iframe that the Site Editor wraps around the template:

<iframe class="edit-site-visual-editor__editor-canvas" aria-label="Editor Canvas" role="button" name="editor-canvas" tabindex="0" src="blob:https://elegant-addax-156c1d.instawp.xyz/7291cd8a-0a26-4dec-89a0-4b0d98ccd472" title="Editor canvas" style="border: 0px; margin-left: auto; margin-right: auto; transition: all 0.3s ease 0s;"></iframe>

Inside this iframe, the service worker is attempting to get installed:

<script type="module">
		import { Workbox } from "https:\/\/elegant-addax-156c1d.instawp.xyz\/wp-content\/plugins\/pwa\/wp-includes\/js\/workbox-v7.0.0\/workbox-window.prod.js";

		if ( 'serviceWorker' in navigator ) {
			window.wp = window.wp || {};
			window.wp.serviceWorkerWindow = new Workbox(
				"https:\/\/elegant-addax-156c1d.instawp.xyz\/wp-admin\/admin-ajax.php?action=wp_service_worker",
				{"scope":"\/wp-admin\/"}			);
			window.wp.serviceWorkerWindow.register();
		}
</script>

And this is where the error is happening.

Two possible solutions here: (1) prevent this script from being injected when in the Site Editor, or (2) prevent attempting to register when the current page is a blob, such as if location.protocol === 'blob:' .

In any case, the error doesn’t seem like it is going to be causing any actual functionality problem other than the console getting populated with the error entry.

@westonruter westonruter added the bug Something isn't working label Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant