0

I am building a Safari extension.

On the manual, at the page about "Adding Contextual Menu Items", at the paragraph "Adding Contextual Menu Items Programmatically", it says:

You can add menu items to the contextual menu by responding to the extension version of the "contextmenu" event in your global page or an extension bar. If you stored information on the event by calling setContextEventUserInfo() in your injected script, you can use that information to help you decide what menu items to add.

Source: https://developer.apple.com/library/archive/documentation/Tools/Conceptual/SafariExtensionGuide/AddingContextualMenuItems/AddingContextualMenuItems.html#//apple_ref/doc/uid/TP40009977-CH4-SW1

Now, I have this code on my injected script (as I am trying to pass the selected text to the background script):

function handleContextMenu(event) {
  var htmlClip = getHtmlClip(event);
  setContextEventUserInfo(htmlClip);
}

Unfortunately that generates this error:

ReferenceError: Can't find variable: setContextEventUserInfo

Unfortunately when I searched setContextEventUserInfo on Google, the only result was the page of the Safari manual!

Can please anybody explain to me how I am supposed to use the setContextEventUserInfo method?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Dan
  • 15,948
  • 20
  • 63
  • 92

1 Answers1

1

This is what you need:

function handleContextMenu(event) {
    var htmlClip = getHtmlClip(event);
    safari.self.tab.setContextEventUserInfo(event, htmlClip);
}
chulster
  • 2,809
  • 15
  • 14