.json file and extension browserAction popup

95 views
Skip to first unread message

Muhammed Waleed Hafeez

unread,
Mar 8, 2021, 9:08:16 AM3/8/21
to Chromium Extensions
I have Three questions:

1- How do I run my .json file through manifest.json just like we run our (.css and .js) files with content_scripts and background_scripts.
2- how to open chrome extension popup when we visit specific site. (i.e.;  when I open the site named "https://www.facebook.com/profile" then instead of clicking the browserAction-button, extension will open automatically means when we visit the set URL.)
3- How do I keep my chrome-extension to stay open on that specific site.

I am new to chrome-extension and I have searched on the internet but didn't find the solution. 
Note: above mentioned problems is needed in my project and i have to do it one or other way. if anyone could help me or guide me , I would really appreciate it.
and Thanks in advance!

ka...@couponfollow.com

unread,
Mar 10, 2021, 6:25:04 AM3/10/21
to Chromium Extensions, mohammed.wa...@gmail.com
Hey!

1. You can bundle the json file with your extension (keep it in the same zip file), expose it via "web_accessible_resources" (not sure if this step is required though) and then use chrome.runtime.getURL https://developer.chrome.com/docs/extensions/reference/runtime/#method-getURL to compute the final URL of your file on runtime and simply fetch it using the URL. Alternatively, if you use webpack or sth else to bundle your extension, you can simply import the JSON file in your JS file and webpack will take care of the rest.

2. I'm not sure if the native popup can be opened without the user's action... But many extensions simply inject a custom popup (simply DOM elements or iFrames) into the website. You do this by specifying that the content script can run automatically on some (or all) URLs. Then in your content script simply create the popup and inject it into the page. More details about the native popup and browser actions here: https://developer.chrome.com/docs/extensions/reference/browserAction/ 

3. Not sure if I follow, but if by "stay open" you mean having a running content script starting on every page automatically, you simply define it in the manifest:

"content_scripts": [
  {
    "matches": ["<all_urls>"],
    "all_frames": false,
    "js": ["your file here"],
    "run_at": "document_start"
}
]

And it just runs.

Reply all
Reply to author
Forward
0 new messages