0

I'm trying to do a Firefox WebExtension to copy the page title to clipboard when I select a context menu option, but it doesn't work. I've seen these examples: context-menu-demo and selection-to-clipboard. But:

  1. If I create a context menu with a background script I can't copy to clipboard.

  2. And if I try to create a context menu with a content_scripts it doesn't work:

    TypeError: browser.contextMenus is undefined
    
Makyen
  • 31,849
  • 12
  • 86
  • 121
Juan Simón
  • 269
  • 2
  • 7

1 Answers1

0

In the code that is run in response to a contextMenus event (contextMenus.onClicked listener, or onclick parameter in contextMenus.create()), you can inject a content script using tabs.executeScript() and copy the document.title to the clipboard from there. The script could be as simple as just static text which you execute with the code property to tabs.executeScript(). The document.title is available to the content script. If you want to include data not available to the content script, you will need to: Pass a parameter to a content script injected using chrome.tabs.executeScript().

Community
  • 1
  • 1
Makyen
  • 31,849
  • 12
  • 86
  • 121