AGamePlayer
AGamePlayer

Reputation: 7736

How do I put the selected text/link in my chrome extension's page context menu?

When I selected some text, the context menu title is updated. For instance:

enter image description here

Is it possible to do this as an extension developer?

My current code:

chrome.contextMenus.create({
  "title":"I WANT THIS UPDATED",
  "contexts":["browser_action"],
  "onclick":function(info, tab) {
    chrome.tabs.create({url: 'https://www.facebook.com/'});
  }
});

Thanks,

Upvotes: 0

Views: 674

Answers (1)

Xan
Xan

Reputation: 77521

Yes, it's possible, but not for browser_action context.

The screenshot you're showing is for selection context.

Quoting the documentation:

When the context is 'selection', you can use %s within the string to show the selected text. For example, if this parameter's value is "Translate '%s' to Pig Latin" and the user selects the word "cool", the context menu item for the selection is "Translate 'cool' to Pig Latin".

See this answer for more info on context types.

Upvotes: 1

Related Questions