Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

右键菜单只在初次安装时显示 #6

Open
naseeihity opened this issue Oct 26, 2016 · 0 comments
Open

右键菜单只在初次安装时显示 #6

naseeihity opened this issue Oct 26, 2016 · 0 comments

Comments

@naseeihity
Copy link

怀疑是ES6 代码 转成 ES5 后,background.js里Chrome的事件监听函数不在顶层了,所以重启浏览器后,相关的事件(contextMenus.create等)都不会重新注册了.

Register to receive any events your extension is interested in each time the event page is loaded. The event page will be loaded once for each new version of your extension. After that it will only be loaded to deliver events you have registered for. This generally means that your event listeners should be added at the top level scope of the event page, otherwise they may not be available when the event page reloads.

chrome.runtime.onInstalled.addListener(() => {
      chrome.contextMenus.create({
        type: 'normal',
        title: 'save page',
        id: 'save_page'
      });
      chrome.contextMenus.create({
        type: 'normal',
        title: 'save selection',
        id: 'save_selection',
        contexts: ['selection']
      });
    });
    chrome.contextMenus.onClicked.addListener(this._handleMenuClick);

直接写在initial()里试试?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant