Javascript function for cleaning aliexpress links doesn't get always executed on Firefox

19 Views Asked by At

I tried to write a script that would clean aliexpress links on item pages. For example this is the only relevant part of aliexpress link: "https://www.aliexpress.com/item/item-number.html" but most links are followed by "?spm=tracking-parameters". I would like to get rid of everything after ".html", my problem is that my code doesn't get executed most of the time on Firefox. (I'm using tampermonkey extension to execute the script). On chromium based browser the script works as intended.

From what I understand this function should be executed on load, but after adding console logs before calling the linkFix() function I found out it doesn't even get called most of the time and I truly do not understand why.

window.onload = () => {
    linkFix();
}


function linkFix() {
    const currentUrl = window.location.href;
    let cleanLink = currentUrl.includes('?');

    if(cleanLink){
    const splitUrl = currentUrl.split("?", 1);
    console.log(splitUrl[0])
    window.location.replace(splitUrl[0]);
    }
}
0

There are 0 best solutions below