0

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,

AGamePlayer
  • 7,404
  • 19
  • 62
  • 119

1 Answers1

1

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.

Xan
  • 74,770
  • 16
  • 179
  • 206
  • 1
    what if I want to make it more customized? For instance, if I select something, it's the text, but if not, it's something else? – AGamePlayer Oct 02 '17 at 12:59
  • 1
    `selection` context only applies when something is selected. Perhaps you're looking for `page` context, which can specify a different menu. – Xan Oct 02 '17 at 13:01
  • good idea, so I think I should use different context menu types to do this. – AGamePlayer Oct 02 '17 at 13:04
  • 1
    @AwQiruiGuo Added a link to an old answer of mine regarding contexts. So possibly you want `all` instead of `page`. – Xan Oct 02 '17 at 13:05