Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
titaniumnetwork-dev
GitHub Repository: titaniumnetwork-dev/Ludicrous
Path: blob/main/corrosion/lib/browser/history.js
1223 views
1
function createHistoryRewriter(ctx) {
2
return function rewriteHistory() {
3
if (ctx.serviceWorker) return;
4
if (ctx.window.History.prototype.pushState) {
5
ctx.window.History.prototype.pushState = new Proxy(ctx.window.History.prototype.pushState, {
6
apply: (target, that, args) => {
7
if (args[2]) args[2] = ctx.url.wrap(args[2], ctx.meta);
8
const ret = Reflect.apply(target, that, args);
9
ctx.updateLocation();
10
return ret;
11
},
12
});
13
};
14
if (ctx.window.History.prototype.replaceState) {
15
ctx.window.History.prototype.replaceState = new Proxy(ctx.window.History.prototype.replaceState, {
16
apply: (target, that, args) => {
17
if (args[2]) args[2] = ctx.url.wrap(args[2], ctx.meta);
18
const ret = Reflect.apply(target, that, args);
19
ctx.updateLocation();
20
return ret;
21
},
22
});
23
};
24
};
25
};
26
module.exports = createHistoryRewriter;
27