Skip to content

Commit

Permalink
feat: handle unknown urls
Browse files Browse the repository at this point in the history
  • Loading branch information
dbajpeyi committed Oct 7, 2024
1 parent 4bf9a8d commit fb423f5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
25 changes: 14 additions & 11 deletions build/integration/contentScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -22114,35 +22114,38 @@
return await withExponentialBackoff(fn)
}

init () {
async animateFromPath (path) {
const animateElement = this.animateElement.bind(this);
const findElement = this.findElement.bind(this);
const { name, style } = URL_ELEMENT_MAP[path] ?? {};
if (name && style) {
const element = await findElement(name);
animateElement(element, style);
}
}

init () {
// FIXME: this is stolen from element-hiding.js, we would need a global util that would do this,
// single page applications don't have a DOMContentLoaded event on navigations, so
// we use proxy/reflect on history.pushState to find elements on page navigations
const animateFromPath = this.animateFromPath.bind(this);
const historyMethodProxy = new DDGProxy(this, History.prototype, 'pushState', {
async apply (target, thisArg, args) {
const pageURL = args[2].split('?')[0];
const { name, style } = URL_ELEMENT_MAP[pageURL];
const element = await findElement(name);
animateElement(element, style);
const path = args[2].split('?')[0];
await animateFromPath(path);
return DDGReflect.apply(target, thisArg, args)
}
});
historyMethodProxy.overload();
// listen for popstate events in order to run on back/forward navigations
window.addEventListener('popstate', async () => {
console.log('pushState URL', window.location.pathname);
const { name, style } = URL_ELEMENT_MAP[window.location.pathname];
const element = await findElement(name);
animateElement(element, style);
await animateFromPath(window.location.pathname);
});

document.addEventListener('DOMContentLoaded', async () => {
console.log('pushState URL', window.location.pathname);
const { name, style } = URL_ELEMENT_MAP[window.location.pathname];
const element = await findElement(name);
animateElement(element, style);
await animateFromPath(window.location.pathname);
});
}
}
Expand Down
27 changes: 16 additions & 11 deletions src/features/password-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,35 +80,40 @@ export default class PasswordImport extends ContentFeature {
return await withExponentialBackoff(fn)
}

init () {
async animateFromPath (path) {
const animateElement = this.animateElement.bind(this)
const findElement = this.findElement.bind(this)
const { name, style } = URL_ELEMENT_MAP[path] ?? {}
if (name && style) {
const element = await findElement(name)
animateElement(element, style)
}
}

init () {
// FIXME: this is stolen from element-hiding.js, we would need a global util that would do this,
// single page applications don't have a DOMContentLoaded event on navigations, so
// we use proxy/reflect on history.pushState to find elements on page navigations
const animateFromPath = this.animateFromPath.bind(this)
const historyMethodProxy = new DDGProxy(this, History.prototype, 'pushState', {
async apply (target, thisArg, args) {
const pageURL = args[2].split('?')[0]
const { name, style } = URL_ELEMENT_MAP[pageURL]
const element = await findElement(name)
animateElement(element, style)
const path = args[2].split('?')[0]
await animateFromPath(path)
return DDGReflect.apply(target, thisArg, args)
}
})
historyMethodProxy.overload()
// listen for popstate events in order to run on back/forward navigations
window.addEventListener('popstate', async () => {
console.log('pushState URL', window.location.pathname)
const { name, style } = URL_ELEMENT_MAP[window.location.pathname]
const element = await findElement(name)
animateElement(element, style)
await animateFromPath(window.location.pathname)
console.log("After popstate")

Check failure on line 110 in src/features/password-import.js

View workflow job for this annotation

GitHub Actions / unit (ubuntu-20.04)

Strings must use singlequote
})

document.addEventListener('DOMContentLoaded', async () => {
console.log('pushState URL', window.location.pathname)
const { name, style } = URL_ELEMENT_MAP[window.location.pathname]
const element = await findElement(name)
animateElement(element, style)
await animateFromPath(window.location.pathname)
console.log("After popstate")

Check failure on line 116 in src/features/password-import.js

View workflow job for this annotation

GitHub Actions / unit (ubuntu-20.04)

Strings must use singlequote
})
}
}

0 comments on commit fb423f5

Please sign in to comment.