How to get chrome to run extensions automatically? - google-chrome-extension

I am trying to develop a chrome extensions. I've developed a few firefox extensions a few years ago. In firefox it was possible to automatically run your extension of the page, and alter the page's content (add HTML and style it). I'd like the extension to automatically change the html, without requiring the user to click a button up in the browser's window.
How to get chrome to run extensions automatically?
Thank you

You just have to declare a content script in your manifest.json, it will be automatically executed on all pages matching the corresponding URL pattern without any user interaction.

Related

For a Chrome extension, can it control other extensions like turning them off?

I'm working on a project where I need to see the page I'm working on without any extension injected code messing up what I see. I want to know if I can create, or if there is currently, an extension that disables all other extensions for xyz page.
No, extensions can only disable other extensions entirely by using chrome.management.setEnabled API. It's like the on/off switch in chrome://extensions page.
The only way to exclude a certain site from being affected by all or some extensions is to add ExtensionSettings policy with runtime_blocked_hosts that contains that site. Note that the entire site is disabled, not just a single URL. Example: {"*": {"runtime_blocked_hosts": ["*://lastpass.com"]}}
A simple workaround for your use case may be to open that page in an incognito window or even in a new browser profile without extensions: click your avatar icon in the toolbar to access the profile tools where you can create and then open a new profile.

How to open a browser within VSCode just like another editor tab

For a VSCode extension i want open browser within VSCode not externally, wherein i can load some URL (https://developers.redhat.com/)
I tried looking into various options to achieve it in VScode extension, what i came across is with help of webview i.e 'vscode.previewHtml' we can pass html content which would be rendered with in VSCode editor tab, but what i have is url to load. Can pass it to iframe but i can't open it in iframe
Another option is to open it in browser but it opens external browser.
what i need is to open a browser within IDE (VSCode), experience should be similar to what we get for 'vscode.previewHtml'
or as we see in IDEs like eclipse where browser window is opened right inside IDE.
As we can see below
Please give inputs, suggestions
It's possible now without extension. Open command palette (CTRL+P) and search for "Simple Browser: Show".
This is how it looks:
In order to render your html you can use the WebView API:
https://code.visualstudio.com/docs/extensions/webview
Microsoft has an extension in development, Live Preview. I use it to view html codecov reports inside of VSCODE and it at least works for that.
You just search for it in extensions and add it to VSCODE

How can I reload my Chrome extension when it is not possible to do so from chrome://extensions because of my extension?

I'm testing out Chrome Extension development and was testing how to do a page redirect through Chrome Extension.
Well it works, but now because of that I can't access the extension settings page.
How do I manually reload/disable the extension? Or do that from the Mac terminal?
My Chrome is pretty much unusable now thanks to my own code.
Thank you!
Tee
Your question seems to be "How can I reload my Chrome extension when it is not possible to do so from chrome://extensions because of my extension?"
A possible answer is:
Press Shift + Esc to open the task manager (or click on the hamburger menu -> More tools -> Task manager).
Select your extension.
Click on the "End process" button.
Now you can visit chrome://extensions and reload your extension in the usual way.
The previous only works if there is an extension process, not if your extension is purely a content script extension. If you still want to use the above method, you can force an extension process to become visible by opening chrome-extension://[extension id here]/manifest.json in a new tab.

Opening a Chrome extension as a pop-up using a link

I have a chrome extension installed in my browser. When I click the extension's icon in the menu bar the extension opens as a floating pop-up, as expected.
What I am trying to do is to open the extension in Chrome via a link/shortcut/whatever from another program. As a first step I've tried opening the extension from the command line, ex:
chrome "chrome-extension://abcdefghijklmnopqrstuvwxyz/index.html"
This works but the extension opens as a new tab and takes up a full broswer page instead of a just being a pop-up. Is there a way to open the extension as a pop-up on top of any open tabs?
Sadly, it's completely impossible.
There is an API in the works, but it would require at a minimum a user gesture, at a maximum explicit invocation of the extension.
So opening a link would not be enough, nor would a Native Message be.
you cant make the native extension popup to show programatically but you could use a content script that displays the popup (using the new for example) on the tab that you want.

how to get the debug information for chrome extension

I write a DOM tree protecter Chrome extension to examine if the DOM tree changes. I have the js files in background_page, how can i get those console.logs() in other test html files? What I can only find now is the debug information of chrome://extensions/ when i click on generated_background_page.html. So how can I get information of other webpages? Thanks for replying.
One thing I have found very useful when debugging chrome extensions is to use the "inspect element" feature of the chrome developer tools. If you have a page or an element (such as on a popup from your extension) that you want to debug:
Open up Developer Tools
Wait for your popup to appear (if its not already up)
Switch to the Elements view on Developer Tools
Click the magnifying glass at the bottom so you can select an element
Click on an element in the page you want to debug (e.g. the popup page)
Now your Sources view and other views line up to match the element you've clicked on. The console will now let you look at variables in that context.
If you are not able to get the extension to work, there could be a whole host of reasons.
Are all your scripts loaded form the extension's directory or are you serving
them from a site? Chrome will not load scripts from an external site
unless over https AND after the site that is serving the script has
been whitelisted. See the Chrome Content Security
Policy
for more info.
To inspect the DOM, you need to inject a content script into the page that is being loaded. Are you sure you are doing this correctly? The manifest.json must be done right or else your content script will not get loaded.
For your content script and extension to communicate, you must post and receive messages. More information is available here.
Perhaps the best suggestion I have is that you follow the Chrome extension "tutorial" carefully until you have something working and then amend it to suit your needs.

Resources