violentmonkey: [BUG] Web Locks API doesn't work with Noscript or uBlock scripts blocked

Sequence of actions:

  1. Install noscript or block scripts by default in uBlock Origin
  2. Install this script:
// ==UserScript==
// @name        Web Locks test
// @match       https://example.com/*
// @grant       none
// @version     1.0
// @author      -
// ==/UserScript==

function delay(ms){
    return new Promise(resolve=>{
        setTimeout(resolve, ms);
    });
}

navigator.locks.request('test', {mode: 'exclusive', ifAvailable: false, steal: false}, async ()=>{
    console.log('Hello, world!');
    await delay(20000);
});
  1. Open two blank tabs and open the consoles
  2. Navigate both tabs to https://example.com

Problem:

Both scripts print hello world immediately. There is also an error (will show below).

Expected result:

One script waits 20 seconds for the lock on the other script to release before printing hello world.

Devtools console contents:

Content Security Policy: The page’s settings blocked the loading of a resource at inline (“script-src”). injected.js:1:8970
Hello, world! Web Locks test.user.js:16:13
Uncaught (in promise) Error: Permission denied to access property "then"

Environment:

  • OS: Debian sid
  • Browser: Firefox 109.0 (64-bit)
  • Violentmonkey Version: v2.13.10

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

We usually don’t add new API first unless it exists in Tampermonkey or elsewhere and is already used by userscripts. If we are to add this API first we need to think it through so that it’s extensible in the future. Maybe you can suggest something here or in Tampermonkey repository, otherwise I don’t think I’ll be doing anything myself as I don’t write such complex scripts.