Answer the question
In order to leave comments, you need to log in
How to make the Chrome extension react to notifications from the site?
There is a certain site that displays a notification to the browser on some event. It is required that the extension for Google Chrome calls a certain function in case a notification pops up from this site.
The first thought is to change the onshow event in the script responsible for notifications, but as far as I understand, I cannot directly modify site scripts through the extension, I can only interact with the DOM and insert my own scripts.
How to be and what to do? Is there an easier way than copying the entire script and pasting it with the necessary changes through the extension into the site, first deleting the old script from the header?
Answer the question
In order to leave comments, you need to log in
The first method, the easiest
In the manifest, list the domains from which you can connect:
"externally_connectable": {
"matches": ["https://somesites.com/*"]
}
if(chrome && chrome.runtime && chrome.runtime.sendMessage){
var editorExtensionId = "уникальный идентификатор раширения";
chrome.runtime.sendMessage(editorExtensionId, {notification:"Some notification"});
}
chrome.runtime.onMessageExternal.addListener(
function(request, sender, sendResponse) {
if (sender.url != "https://somesites.com")
return;
showNotification(request.notification);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question