-
-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
send message from background to contentscript/web page? #54
Comments
This template has in browser.runtime.onInstalled.addListener(function() {
chrome.contextMenus.create({
title: "Mage - Explain Code",
contexts: ["selection"],
id: "Mage - Explain Code"
});
});
// This function is serialized, sent to content context, deserialized, and then executed,
// so all external variables will be lost. Use arguments instead.
function handler(code) {
console.log('Hello world!');
console.log(code);
}
browser.contextMenus.onClicked.addListener(function (info, tab) {
if (info.menuItemId === "Mage - Explain Code") {
let code = info.selectionText;
// Use args to pass arguments to handler
browser.scripting.executeScript({target: {tabId: tab.id}, func: handler, args: [code]});
}
}) |
@bershanskiy thanks I am trying to import
|
@jryebread This error is expected, since browser.scripting.executeScript({target: {tabId: tab.id}, func: executeTippy}); It is almost like calling
|
Hi there, I was wondering:
why this starter doesn't have a content script to be able to read the DOM of the web page
I am trying to create a context menu (which works fine) in backgroundPage.ts:
when the context menu button is pressed it should send a message to the current tab and open a tool tip on the highlighted text in the web page.
Which file should I handle this message in? Can this be done inside the popup folder component.tsx, or do I need to create a content script file somehow?
I have spent all day struggling with how to do this so I would very much appreciate help! thank you!
The text was updated successfully, but these errors were encountered: