SecurityError: The operation is insecure - window.history.pushState()

前端 未结 9 1990
我寻月下人不归
我寻月下人不归 2020-11-28 08:56

I\'m getting this error in Firefox\'s Console: SecurityError: The operation is insecure and the guilty is HTML5 feature: window.history.pushState()

相关标签:
9条回答
  • 2020-11-28 09:27

    In my case I was missing 'www.' from the url I was pushing. It must be exact match, if you're working on www.test.com, you must push to www.test.com and not test.com

    0 讨论(0)
  • 2020-11-28 09:32

    replace serviceWorker.unregister() to serviceWorker.register() in index.js file

    0 讨论(0)
  • 2020-11-28 09:34

    Make sure you are following the Same Origin Policy. This means same domain, same subdomain, same protocol (http vs https) and same port.

    How does pushState protect against potential content forgeries?

    EDIT: As @robertc aptly pointed out in his comment, some browsers actually implement slightly different security policies when the origin is file:///. Not to mention you can encounter problems when testing locally with file:/// when the page expects it is running from a different origin (and so your pushState assumes production origin scenarios, not localhost scenarios)

    0 讨论(0)
  • 2020-11-28 09:35

    When creating a PWA, a service worker used on an non https server also generates this error.

    0 讨论(0)
  • 2020-11-28 09:38

    I had the same problem when called another javascript file from a file without putting javascript "physical" address. I solved it by calling it same way from the html, example: "JS / archivo.js" instead of "archivo.js"

    0 讨论(0)
  • 2020-11-28 09:45

    I solved it by switching tohttp protocol from the file protocol.

    • you can use "live-server" extension in VS code,
    • or, on node, use live-server [dirPath]
    0 讨论(0)
提交回复
热议问题