开发者

Javascript: Delaying display of the context menu (Chrome)

I'm trying to dynamically create context menu items in a Chrome extension; this involves sending a request to the main extension process to modify the menu, and blocking the menu from being displayed until a response is sent. I've been experimenting with different solutions all day, and I have yet to come up with one that works. For example,

node.oncontextmenu = initContext({...});

initContext = function(menuParams) {
  return function(event) {
    if (event.showContext) // Menu has been created and is ready for display
      return true;

    event.preventDefault(); // Block original menu event
    chrome.extension.sendReques开发者_开发百科t(menuParams, function() { // Send request to modify menu,
      event.showContext = true; // generate new event when menu is ready
      event.target.dispatchEvent(event);
    });
  };
};

The menu is blocked with preventDefault(), and the callback function to chrome.extension.sendRequest() is executed when the menu is ready to be displayed. With this solution (and all the others I've tried), the menu is never displayed. I'd appreciate any help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜