Conversaciones » Desarrolladores

Firefox "blocks" this GM script and doesn't even appear in the debugger

§
Publicado: 22/8/2022
Editado: 22/8/2022

This code, for some reason causes firefox to not even reconize this script (does not execute it, nor will it show up on debugger sources), can anyone tell me why?

// ==UserScript==
// @name     Unnamed Script 692044
// @version  1
// @grant    GM.setValue
// @grant    GM.getValue
// @include      *
// ==/UserScript==

'use strict';


(function() {
	const ListOfURLs = `
https://google.com
https://wikipedia.org
	`
	window.addEventListener('load', LoadURLAfterTimer)
	
	function LoadURLAfterTimer() {
		console.log("test")
		setTimeout(LoadAnotherPage, 5000)
	}
	
	
	function LoadAnotherPage() {
		let URL_index = await GM.getValue("URLIndex", -1);
		URL_index++
		await GM.setValue("URLIndex", URL_index);
		location.href = ListOfURLs.match(/http(s)?\:\/\/(?!data:)[^\s\"\']+/g)[URL_index] //Code stops executing after this executes.
	}
})();

I'm trying to write a code that causes the browser to go from one URL to another URL after a delay, without opening any additional tabs.

§
Publicado: 23/8/2022
Editado: 23/8/2022

At least one reason - the use of 'await' - does this help? :: https://stackoverflow.com/questions/53939882/why-isnt-await-working-with-async-on-firefox

§
Publicado: 23/8/2022

At least one reason - the use of 'await' - does this help? :: https://stackoverflow.com/questions/53939882/why-isnt-await-working-with-async-on-firefox

Well, another problem: NaN. Updated code.

// ==UserScript==
// @name     Unnamed Script 692044
// @version  1
// @grant    GM.setValue
// @grant    GM.getValue
// @include      *
// ==/UserScript==

'use strict';


(function() {
	const ListOfURLs = `
https://google.com
https://wikipedia.org
	`
	window.addEventListener('load', LoadURLAfterTimer)
	
	function LoadURLAfterTimer() {
		console.log("test")
		setTimeout(LoadAnotherPage, 5000)
	}
	
	
	function LoadAnotherPage() {
		let URL_index = GM.getValue("URLIndex", -1).then();
		URL_index++
		GM.setValue("URLIndex", URL_index).then();
		location.href = ListOfURLs.match(/http(s)?\:\/\/(?!data:)[^\s\"\']+/g)[URL_index] //Code stops executing after this executes.
	}
})();

for some reason, URL_index is supposed to be set to -1 by default if there is no value for it: https://wiki.greasespot.net/GM.getValue

Publicar respuesta

Inicia sesión para responder.