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

Error in console when trying to communicate with service worker in Firefox with persistant cookies disabled #17136

Closed
Findus23 opened this issue Jan 22, 2021 · 1 comment · Fixed by #17139
Assignees
Labels
Bug For errors / faults / flaws / inconsistencies etc.
Milestone

Comments

@Findus23
Copy link
Member

As reported on the forum: https://forum.matomo.org/t/firefox-84-promiseerror-securityerror-the-operation-is-insecure/40299/6?u=lukas

This can be reproduced by creating a fresh firefox profile (84.0.2 in my case), and opening forum.matomo.org.

Failed to get service worker registration(s): Storage access is restricted in this context due to user settings or private browsing mode. _application-581e2539c09b2579657fb9679aaeeb510ddf1d491cdaf95d59f45e52559d6843.js:71615:34

Failed to register/update a ServiceWorker for scope ‘https://forum.matomo.org/’: Storage access is restricted in this context due to user settings or private browsing mode. _application-581e2539c09b2579657fb9679aaeeb510ddf1d491cdaf95d59f45e52559d6843.js:71633:34

Failed to register Service Worker: SecurityError: The operation is insecure. _application-581e2539c09b2579657fb9679aaeeb510ddf1d491cdaf95d59f45e52559d6843.js:71635:20

Uncaught (in promise) DOMException: The operation is insecure. _application-581e2539c09b2579657fb9679aaeeb510ddf1d491cdaf95d59f45e52559d6843.js:1

​It seems like even if no service worker (for offline tracking) is set up, just trying to communicate with it fails.

matomo/js/piwik.js

Lines 6969 to 6977 in cc25c84

// initialize the Matomo singleton
addEventListener(windowAlias, 'beforeunload', beforeUnloadHandler, false);
addEventListener(windowAlias, 'online', function () {
if (isDefined(navigatorAlias.serviceWorker) && isDefined(navigatorAlias.serviceWorker.ready)) {
navigatorAlias.serviceWorker.ready.then(function(swRegistration) {
return swRegistration.sync.register('matomoSync');
});
}
}, false);

I guess the solution is either to make sure Matomo doesn't try to communicate with it when offline tracking is not set up (maybe even add an option to the regular tracking code if one wants to use offline tracking) or catch the promise, ignore it and document it in the offline tracking docs.

@Findus23 Findus23 added the Bug For errors / faults / flaws / inconsistencies etc. label Jan 22, 2021
@tsteur
Copy link
Member

tsteur commented Jan 24, 2021

Thanks @Findus23 been debugging this:
Screenshot 2021-01-25 at 12 29 14 PM

seems Firefox does not support "sync" yet see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/sync

Created #17139 which should fix the issue.

The error should also only happen when the "online" event is triggered meaning when you were offline and become "online".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants