简体   繁体   中英

How to get information about a chrome extension from the extension url?

I have a chrome extension installed which has a built-in browser(which presumably just loads a page in an iframe). Using this built-in browser I navigate to my locally hosted react app at localhost:3000 , console logging window.location gives an indication that the page is nested within a chrome extension as window.location.ancestorOrigins has a length of 1 with a value of chrome-extension://gjagmgiddbbciopjhllkdnddhcglnemk at index 0; how can I get information about this chrome extension such as its name from this URL or any other way of doing so if this way is not possible?

If I understand correctly, you want more info about an extension with an ID saved into this URL in your question.

So there is a simple way to do it using extension API.

  1. You could use get method from management API . It has id param in the query so that you will receive a single element as a response.

  2. If you want to pull data about all extensions that are installed you could simply use getAll method from the same API I showed before.

If you receive this ID in content-script. Then use runtime API to send this ID to the MV3 service worker and parse it as described above.

MV3 API provides promises. I showed an example for Chrome API, but it wold work for other common browsers. Also, you could find this method on the extension API polyfill.

Hope this would help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM