How to get my extension's id from JavaScript?

后端 未结 3 1457
滥情空心
滥情空心 2020-12-23 09:32

I\'m writing a Chrome extension, I need to get my extension\'s id in my code, so I don\'t need to change it manually every time. How can I do this?

3条回答
  •  旧巷少年郎
    2020-12-23 10:03

    You can get it like this (no extra permissions required) in two different ways:

    1. Using runtime api: var myid = chrome.runtime.id;

    2. Using i18n api: var myid = chrome.i18n.getMessage("@@extension_id");

    but you don't need it for opening pages, as chrome.tabs.create() (and some others) understand relative paths.

    So to open index.html from your extension folder you should just use:

    chrome.tabs.create({url: "index.html"});
    

提交回复
热议问题