I'm trying to re-write some of my Tampermonkey scripts to use some of the built in TM/GM functions, but I can't get them to work. An example is the GM_Notification function.
I'm testing it out using the example GM_notification from the documentation. Here is the complete userscript file contents:
// ==UserScript==
// @name Test Notification
// @namespace http://tampermonkey.net/
// @version 2024-01-06
// @description try to take over the world!
// @author You
// @match https://gist.github.com/EtienneDG/fe32d3213d87f79e0da0f829e73ee4ab
// @icon https://www.google.com/s2/favicons?sz=64&domain=github.com
// @grant GM_notification
// @grant GM.notification
// @grant unsafeWindow
// @sandbox JavaScript
// ==/UserScript==
(function() {
'use strict'
console.log('Loaded test notification')
console.log('About to execute GM_notification...');
GM_notification({
text: "This is the notification message.",
title: "Notification Title",
url: 'https:/google.com/',
onclick: (event) => {
// The userscript is still running, so don't open example.com
event.preventDefault();
// Display an alert message instead
alert('I was clicked!')
},
});
console.log('Executed GM_notification')
})()
And when I go to the page that loads this script, I get absolutely no notification/alert, or even an error. The console output is below:
content: normal start event processing for lr2kbof7.baa (1 to run)
VM3242 content.js:55 env: schedule "Test Notification" for document-idle
VM3242 content.js:53 env: inject "Test Notification" now
VM3242 content.js:73 content: DOMContentLoaded
VM3242 content.js:54 env: run "Test Notification" now (0 requires)
userscript.html?name=Test-Notification.user.js&id=a8f4d506-9af0-45b8-8eed-362488ac963e:21 Loaded test notification
userscript.html?name=Test-Notification.user.js&id=a8f4d506-9af0-45b8-8eed-362488ac963e:23 About to execute GM_notification...
userscript.html?name=Test-Notification.user.js&id=a8f4d506-9af0-45b8-8eed-362488ac963e:37 Executed GM_notification
VM3242 content.js:73 content: load
So the script clearly runs, but I don't see any notification or any error in the console logs.
I have tried using the async GM.notification as well:
// ==UserScript==
// @name Test Notification
// @namespace http://tampermonkey.net/
// @version 2024-01-06
// @description try to take over the world!
// @author You
// @match https://gist.github.com/EtienneDG/fe32d3213d87f79e0da0f829e73ee4ab
// @icon https://www.google.com/s2/favicons?sz=64&domain=github.com
// @grant GM_notification
// @grant GM.notification
// @grant unsafeWindow
// @sandbox JavaScript
// ==/UserScript==
(async function() {
'use strict'
console.log('Loaded test notification')
console.log('About to execute await GM.notification...');
const clicked = await GM.notification({ text: "Click me." });
console.log('clicked:',clicked)
console.log('Executed await GM.notification')
})()
But it was the same thing (no notification or errors)
I have tried a few things while debugging:
- Trying with the other
@sandboxvalues: MAIN_WORLD, ISOLATED_WORLD, USERSCRIPT_WORLD, raw, DOM - Does't seem to be any permissions issues with the TM plugin or script
- The Add GM functions to this or window is set to On in the script settings
- Set Run At to: document-start, document-body, document-end
- For the Position setting, I tried 1, 3 and 7
- Consulted the Google Gods, and found some similar threads (Example: Uncaught ReferenceError: GM_notification is not defined), but ultimately I haven't found anything that fixes it.
Local Specs:
- OS: macOS Big Sur
- Browser: Chrome Version 120.0.6099.129 (Official Build) (x86_64)
- Tampermonkey Version: v5.0.0
Any help would be appreciated. Thank you.
I found the answer (thanks to this).
It wasn't the extension settings or security settings within Chrome, but the system security systems for Chrome. I went to my System Preferences > Notifications > Looked for Chrome and noticed it was disabled:
Once enabled, the notifications worked just fine.
Thanks!