Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

window.onurlchange skips hash change #2339

Open
7nik opened this issue Jan 21, 2025 · 1 comment
Open

window.onurlchange skips hash change #2339

7nik opened this issue Jan 21, 2025 · 1 comment

Comments

@7nik
Copy link

7nik commented Jan 21, 2025

Example:

// ==UserScript==
// @name         Test urlchange
// @namespace    http://tampermonkey.net/
// @version      2025-01-21
// @description  try to take over the world!
// @author       You
// @match        https://example.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=example.com
// @grant        window.onurlchange
// ==/UserScript==

const div = document.querySelector("div");
div.insertAdjacentHTML("beforeend", `
<a href="/" class="link">root</a>
<a href="/sub" class="link">/sub</a>
<a href="#foo" class="link">#foo</a>
<a href="#bar" class="link">#bar</a>
<a href="#test" class="link">#test</a>
<br>
<textarea placeholder="logs" readonly cols=72 rows=20></textarea>
`);
const textarea = div.lastElementChild;

window.addEventListener("click", (ev) => {
    if (!ev.target.classList.contains("link")) return;
    ev.preventDefault();
    window.history.pushState(null, "", ev.target.href);
}, true);

window.addEventListener("urlchange", () => {
    textarea.value += window.location.href + "\n";
});

Go to https://example.com/ and click the links.

Expected

Each navigation is logged

Actual

Hash change isn't logged, while path change and clicking the same link is logged.

TM v5.3.3

P.S.: the issue template is gone (not supported anymore) and should be re-added via the new method

@derjanb derjanb added the bug label Jan 22, 2025
@derjanb derjanb added this to the 5.4 milestone Jan 22, 2025
@derjanb
Copy link
Member

derjanb commented Jan 25, 2025

Thanks a lot for reporting!

The issue should be fixed at 5.4.6225 (crx)

Please download the crx file linked above and drag and drop it to the extensions page chrome://extensions (after you've enabled 'Developer Mode').

For a quick fix please export your settings and scripts as zip or (JSON) file at the "Utilities" tab and import it back at the fixed BETA version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants