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

"SecurityError: The operation is insecure" on Firefox #248

Open
szepeviktor opened this issue Mar 3, 2020 · 10 comments
Open

"SecurityError: The operation is insecure" on Firefox #248

szepeviktor opened this issue Mar 3, 2020 · 10 comments

Comments

@szepeviktor
Copy link
Contributor

Please check the returned Promise. It could be rejected with a certain cookie setting
See https://bugzilla.mozilla.org/show_bug.cgi?id=1429714#c1

kép

@westonruter
Copy link
Collaborator

So we're missing a catch() call here?

navigator.serviceWorker.register(
<?php echo wp_json_encode( wp_get_service_worker_url( $name ) ); ?>,
<?php echo wp_json_encode( compact( 'scope' ) ); ?>
).then( reg => {
<?php if ( WP_Service_Workers::SCOPE_ADMIN === $name ) : ?>
document.cookie = <?php echo wp_json_encode( sprintf( 'wordpress_sw_installed=1; path=%s; expires=Fri, 31 Dec 9999 23:59:59 GMT; secure; samesite=strict', $scope ) ); ?>;
<?php endif; ?>
<?php if ( ! wp_service_worker_skip_waiting() ) : ?>
reg.addEventListener( 'updatefound', () => {
if ( ! reg.installing ) {
return;
}
updatedSw = reg.installing;
/* If new service worker is available, show notification. */
updatedSw.addEventListener( 'statechange', () => {
if ( 'installed' === updatedSw.state && navigator.serviceWorker.controller ) {
const notification = document.getElementById( 'wp-admin-bar-pwa-sw-update-notice' );
if ( notification ) {
notification.style.display = 'block';
}
}
} );
} );
<?php endif; ?>
} );

@szepeviktor
Copy link
Contributor Author

Seems like...

@westonruter
Copy link
Collaborator

Would you like to open a PR? Should it be putting the error in the console via console.error()?

@szepeviktor
Copy link
Contributor Author

Thank you for your offer! I better not touch frontend code.

@westonruter
Copy link
Collaborator

I can't reproduce this issue. In private browsing, navigator.serviceWorker is not even defined. The same goes if I select to not remember history in non-private browsing.

@szepeviktor
Copy link
Contributor Author

szepeviktor commented Mar 4, 2020

Try telling Firefox to delete cookies on exit - that is mentioned in the bug tracker.
about:preferences#privacy

kép

@westonruter
Copy link
Collaborator

OK, I can see that now:

Screen Shot 2020-03-04 at 21 14 34

With this patch:

diff --git a/wp-includes/service-workers.php b/wp-includes/service-workers.php
index 2197787..17cb864 100644
--- a/wp-includes/service-workers.php
+++ b/wp-includes/service-workers.php
@@ -183,6 +183,9 @@ function wp_print_service_workers() {
 									} );
 								} );
 							<?php endif; ?>
+						} )
+						.catch( ( err ) => {
+							console.info( "Service worker will not be installed due to:", err );
 						} );
 
 						<?php if ( is_admin_bar_showing() && ! wp_service_worker_skip_waiting() ) : ?>

The result is:

Screen Shot 2020-03-04 at 21 15 47

Doesn't seem a whole lot better.

@szepeviktor
Copy link
Contributor Author

szepeviktor commented Mar 5, 2020

@westonruter
Copy link
Collaborator

westonruter commented Mar 6, 2020

No, I don't think that is right. The reject is already being called today by the browser today. When a rejected promise is not caught via catch then it shows up on the console as an error. You can see from my code above that adding catch does prevent the error from showing in the console, but the Firefox DevTools still shows another error regardless. So I don't know how much benefit there is to catch it in the first place.

@szepeviktor
Copy link
Contributor Author

Yes, we have the same problem as others in the Mozilla bug:

Neither try/catch nor then/catch seems to be able to supress the error warnings in the console.

https://bugzilla.mozilla.org/show_bug.cgi?id=1429714#c12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants