Opera notification not working
-
kophaiem79 last edited by
Opera 116.0.5366.71
Windows 10 22H2 (0s build 19045.5371) Enterprise
My extension can push notification to windows but when user click button it not working (older version Opera 99 and other browser like newest Chrome still work!). Seem chrome.notifications.onButtonClicked.addListener not working. i want to know if it was bug or find a way to stop using native notification only browser notification. -
leocg
-
kophaiem79 last edited by leocg
File 1: notifier.js
let url=window.location.href; if(url.indexOf('example.com')>-1){ document.addEventListener('click',()=>{ chrome.runtime.sendMessage(chrome.runtime.id,{data:'test'}); }) }
File 2:
chrome.runtime.onMessage.addListener(data =>{ let m='notifier_id'; chrome.notifications.create(m, {title:'Demo title',message:'This is demo',type:'basic',requireInteraction:true,buttons: [{ title: 'Open' },{ title: 'Close' }]}); chrome.notifications.onButtonClicked.addListener(function(m,btnIdx){ if (btnIdx === 0) { console.log('Open new tab'); chrome.tabs.create({ url: 'https://google.com' }); chrome.notifications.clear(m); return false; } else if (btnIdx === 1){ chrome.notifications.clear(m); } }); })
File 3:
{ "name": "Notifier Demo", "version": "1.0.0.0", "manifest_version": 3, "description": "Notifier Demo", "content_scripts": [ { "matches": ["https://www.example.com/"], "js": ["notifier.js"], "all_frames":true } ], "permissions": [ "notifications","tabs" ], "background":{"service_worker":"background.js"} }
How it work: go to https://www.example.com/, click anywhere will create a notifier. Click Open will open new tab google.com. Work on Edge, Chrome and old Opera browser. Not in my current version.
-
burnout426 Volunteer last edited by
@kophaiem79 I get:
Unchecked runtime.lastError: Some of the required properties are missing: type, iconUrl, title and message. Context Unknown Stack Trace :0 (anonymous function)
when clicking on the example.com page (in Chrome too).
-
kophaiem79 last edited by
@burnout426
File: background.js
chrome.runtime.onMessage.addListener(data =>{
let m='notifier_id';
chrome.notifications.create(m, {title:'Demo title',message:'This is demo',iconUrl: 'icon128.png',type:'basic',requireInteraction:true,buttons: [{ title: 'Open' },{ title: 'Close' }]});
chrome.notifications.onButtonClicked.addListener(function(m,btnIdx){
if (btnIdx === 0)
{
console.log('Open new tab');
chrome.tabs.create({ url: 'https://google.com' });
chrome.notifications.clear(m);
return false;} else if (btnIdx === 1){ chrome.notifications.clear(m); } });
})
Save icon (name:icon128.png) in same folder. -
burnout426 Volunteer last edited by
That fixed the extension. However, testing on Windows 11 23H2, clicking at https://www.example.com/ wasn't triggering a notification at all in Opera.
However, I noticed that Opera wasn't listed in "Settings -> System -> Notifications" in Windows, so I went to https://cleverpush.com/en/test-notifications/, clicked "Greetings", chose "allow" and clicked "Greetings" again to show a notification in Opera and that added Opera to the notification settings in Windows.
Then, I cleared notifications by clicking the clock in the Windows systray to bring up notifications and clicked "Clear".
Then, I tried your extension in Opera again and clicking on the https://www.example.com/ page starting working and showing the notification. Clicking "open" on the notification doesn't do anything though. I don't think the ButtonClicked event is firing for some reason in Opera, just like you said. According to https://help.opera.com/en/extensions/apis/, Opera does have some limitations on the notifications API, but nothing specific to the firing of the event.
I also deleted all entries from "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings" in the registry and restarted Opera. Even though Opera was no longer listed in the Windows notification settings, your notification popup was still showing up.
So, there's definitely some quirkyness going on there. But yes, I can confirm the event listener issue in Opera. Sounds like a bug to me.