In order to ease development i want to serve the necessary TM @require
files through a localhost HTTP(S) server. I expected these files to be reloaded on each page reload.
The files are fetched from the localhost server when i update the UserScript in the TM editor, however, they are not fetched when a matched URL is loaded. I'm not sure if this is a caching thing by TM or if i'm doing something wrong here.
To separate concerns in the JS files, the UserScript header is separated from other logic. The necessary files are imported using @required. This is the content of the UserScript file that is pasted in the TM editor:
// ==UserScript==
// @name myName
// @description myDescription
// @author robinlarondelle
// @version 0.1
// @namespace myNameSpace
// @homepage myHomePage
// @include *linkedin.com/*
// @icon https://www.google.com/s2/favicons?domain=linkedin.com
// @grant window.onurlchange
// @require https://localhost:3000/public/myScript.user.js
// ==/UserScript==
The localhost HTTPS static file server is a Node.JS server with a self signed certificate to enable HTTPS. When using Postman and FireFox after providing my .pem
file, the server works as expected. If necessary i can provide more details about the server, but i don't think the problem resides here.
FireFox prohibits accessing local files from TM (see this comment). So one alternative to this problem would be to just use Chrome, as it does support accessing local files. However, i want to abstain from using local files because there are multiple developers working on this project. I also don't want to limit development to one specific browser.
The main question/problem is: Why does @require
from the UserScript header only fetch the required files on Script Save in the TM editor, but not on Page Reload when the URL matches? Is this normal behavior and/or can we turn this off?
I have created a GitHub issue on the Tampermonkey repository as well and someone came up with the solution:
Set "Externals" update frequency to "Always". This will fetch the @require
tag on page reload. This does however not run smoothly and most of the time it will fetch after page reload (so you have to reload twice).
Anyways, this solved the problem for me.