Skip to content

Instantly share code, notes, and snippets.

@syoichi
Last active February 6, 2023 16:26
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syoichi/3747507 to your computer and use it in GitHub Desktop.
Save syoichi/3747507 to your computer and use it in GitHub Desktop.
Chrome拡張で自身のIDを取得する方法
// ref. http://stackoverflow.com/questions/12471316/what-is-the-best-way-to-retrieve-a-google-chrome-extension-id
// https://plus.google.com/100132233764003563318/posts/Ct39rw4DWGE
chrome.i18n.getMessage('@@extension_id');
// via https://github.com/Constellation/taberareloo/blob/d1299f052f14a3dfcb212eda0e3428c5f5c8a027/src/lib/content.js#L79
chrome.extension.getURL('').match(/chrome-extension:\/\/([^\/]+)\//)[1];
// Content Scriptでは動作しない
chrome.app.getDetails().id;
// via https://developer.chrome.com/extensions/runtime.html
// バージョン22より使用可能
chrome.runtime.id;
chrome.runtime.getURL('').match(/chrome-extension:\/\/([^\/]+)\//)[1];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment