mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 17:41:40 -05:00
Fix #4469: wrap history events in try/catch
This commit is contained in:
parent
923e5e9411
commit
78d0fa91df
1 changed files with 33 additions and 27 deletions
|
@ -41,40 +41,46 @@ config.getAsync("superignore").then(async TRI_DISABLE => {
|
||||||
|
|
||||||
if (TRI_DISABLE === "true") return
|
if (TRI_DISABLE === "true") return
|
||||||
|
|
||||||
// Add cheap location change event
|
try {
|
||||||
// Adapted from: https://stackoverflow.com/questions/6390341/how-to-detect-if-url-has-changed-after-hash-in-javascript
|
|
||||||
//
|
|
||||||
// Broken atm - on https://github.com/tridactyl/tridactyl/pull/3938 clicking onto issues doesn't do anything and we get "permission denied to access object"
|
|
||||||
|
|
||||||
const realwindow = (window as any).wrappedJSObject ?? window // wrappedJSObject not defined on extension pages
|
// Add cheap location change event
|
||||||
|
// Adapted from: https://stackoverflow.com/questions/6390341/how-to-detect-if-url-has-changed-after-hash-in-javascript
|
||||||
|
//
|
||||||
|
// Broken atm - on https://github.com/tridactyl/tridactyl/pull/3938 clicking onto issues doesn't do anything and we get "permission denied to access object"
|
||||||
|
|
||||||
const triPushState = (hist => (
|
const realwindow = (window as any).wrappedJSObject ?? window // wrappedJSObject not defined on extension pages
|
||||||
(...args) => {
|
|
||||||
const ret = hist(...args)
|
const triPushState = (hist => (
|
||||||
realwindow.dispatchEvent(new Event("HistoryPushState"))
|
(...args) => {
|
||||||
|
const ret = hist(...args)
|
||||||
|
realwindow.dispatchEvent(new Event("HistoryPushState"))
|
||||||
|
realwindow.dispatchEvent(new Event("HistoryState"))
|
||||||
|
return ret
|
||||||
|
})
|
||||||
|
)(realwindow.history.pushState.bind(realwindow.history))
|
||||||
|
|
||||||
|
const triReplaceState = (hist => (
|
||||||
|
(...args) => {
|
||||||
|
const ret = hist(...args)
|
||||||
|
realwindow.dispatchEvent(new Event("HistoryReplaceState"))
|
||||||
|
realwindow.dispatchEvent(new Event("HistoryState"))
|
||||||
|
return ret
|
||||||
|
})
|
||||||
|
)(realwindow.history.replaceState.bind(realwindow.history))
|
||||||
|
|
||||||
|
realwindow.addEventListener("popstate", () => {
|
||||||
realwindow.dispatchEvent(new Event("HistoryState"))
|
realwindow.dispatchEvent(new Event("HistoryState"))
|
||||||
return ret
|
|
||||||
})
|
})
|
||||||
)(realwindow.history.pushState.bind(realwindow.history))
|
|
||||||
|
|
||||||
const triReplaceState = (hist => (
|
history.replaceState = triReplaceState
|
||||||
(...args) => {
|
history.pushState = triPushState
|
||||||
const ret = hist(...args)
|
|
||||||
realwindow.dispatchEvent(new Event("HistoryReplaceState"))
|
|
||||||
realwindow.dispatchEvent(new Event("HistoryState"))
|
|
||||||
return ret
|
|
||||||
})
|
|
||||||
)(realwindow.history.replaceState.bind(realwindow.history))
|
|
||||||
|
|
||||||
realwindow.addEventListener("popstate", () => {
|
typeof(exportFunction) == "function" && exportFunction(triReplaceState, history, {defineAs: "replaceState"})
|
||||||
realwindow.dispatchEvent(new Event("HistoryState"))
|
typeof(exportFunction) == "function" && exportFunction(triPushState, history, {defineAs: "pushState"})
|
||||||
})
|
|
||||||
|
|
||||||
history.replaceState = triReplaceState
|
} catch (e) {
|
||||||
history.pushState = triPushState
|
console.error(e)
|
||||||
|
}
|
||||||
typeof(exportFunction) == "function" && exportFunction(triReplaceState, history, {defineAs: "replaceState"})
|
|
||||||
typeof(exportFunction) == "function" && exportFunction(triPushState, history, {defineAs: "pushState"})
|
|
||||||
|
|
||||||
const controller = await import("@src/lib/controller")
|
const controller = await import("@src/lib/controller")
|
||||||
const excmds_content = await import("@src/.excmds_content.generated")
|
const excmds_content = await import("@src/.excmds_content.generated")
|
||||||
|
|
Loading…
Add table
Reference in a new issue