2

I like to keep my personal userscripts on local storage that syncs to the cloud. What I have been doing in the past is simply backing them up but then I realized I can use the @require tag to link to my local version of the file which I can then edit in my IDE.

This worked for a while but stopped working for some reason about 2 years ago and I would like to solve this issue as I am using userscripts more and more these days.

I'm using Google Chrome, Tampermonkey and MacOS.

Here is an example of my userscript code. Please be advised that I'm certain the path is correct.

// ==UserScript==
// @name         Google Mods
// @run-at       document-start
// @namespace    http://google.com/
// @version      1.00
// @description  Google mods
// @author       John Doe
// @match        https://*.google.com/*
// @require      file://⁨/Users/johndoe/Desktop/google.user.js
// ==/UserScript==

When I look at the console when viewing the page I can tell that it is attempting to load the script but cannot find it. This is what the error looks like

Tampermonkey: couldn't load @require from forbidden URL file://⁨/Users/johndoe/Desktop/google.user.js

Any help as to what I am missing would be greatly appreciated.

EDIT: To be clear I have the extension setting Allow access to file URLs enabled.

Michael
  • 33
  • 3
  • 8
  • You need to enable `file access` checkbox on chrome://extensions page in Tampermonkey's details. – wOxxOm Jul 01 '21 at 19:45
  • Thanks for your comment. I am certain that I have that check. I'll edit my original post to clarify. – Michael Jul 02 '21 at 00:28
  • So the error is thrown by Tampermonkey which means you also need to allow file access in Tampermonkey's settings. For example I see "Allow scripts to access local files" when switching TM to advanced mode. – wOxxOm Jul 02 '21 at 03:21

2 Answers2

3
  1. Type in the chrome search bar: chrome://extensions.
  2. Then search for: Tampermonkey.
  3. When you find the tampermonkey extension click on details.
  4. Navigate almost to the end and enable the option: allow access to file urls.

I hope it helps, greetings

search tampermonkey enable the option to allow URLs

Andy Romero
  • 425
  • 5
  • 12
1

By default, extensions in modern browsers do not have access to local file system for security reasons. Therefore, the userscript manager will not be able to load file://⁨/Users/johndoe/Desktop/google.user.js

Greasemonkey is a Firefox extension and on Firefox there is no option to allow file system access.

As explained by wOxxOm, on Tampermonkey for Chrome it is possible to allow access to allow access to local file URIs.

More info: Chrome extension - how to access local file:// with manifest v3

erosman
  • 7,094
  • 7
  • 27
  • 46
  • Chrome extensions can do it (and always could) after the user manually enabled file access on chrome://extensions page in extension's details. – wOxxOm Jul 02 '21 at 07:36
  • @wOxxOm The post has Greasemonkey tag which is Firefox extension so I thought the poster is looking for a universal solution. – erosman Jul 02 '21 at 09:30
  • 1
    The tag was added incorrectly judging by the contents of the question so the answer is incorrect too since it doesn't address the user's main case - Tampermonkey. You can fix it by describing that userscript extensions for Chrome in general can access files and how to configure Tampermonkey to allow file access. – wOxxOm Jul 02 '21 at 12:14