Skip to content

Instantly share code, notes, and snippets.

View mohammedrahman-e2x's full-sized avatar

Mohammed Rahman mohammedrahman-e2x

View GitHub Profile
@mohammedrahman-e2x
mohammedrahman-e2x / detect-url-change.js
Created August 15, 2023 13:02
Detect when URL changes in an SPA from externally injected script
// Set up a mutation observer to watch for url change to detect navigation
var previousUrl = location.href;
var observer = new MutationObserver(function(mutations) {
// If URL changes...
if (location.href !== previousUrl) {
previousUrl = location.href;
// Close popup
removeBanner();