Load chrome extension url in another chrome extension - javascript

I am making a chrome extension which overrides new tab. But I want to make new tab overriding optional. This is not possible in a proper non-hackish way, as override rule is entered in the manifest and is not possible to change it at runtime.
To solve this I have decided to make a separate extension. This separate extension will override the new tab (not the main extension) and will open the main extension webpage in the new tab (chrome-extension://hclbghnhiklgejahckgmpldjgfgleofc/index.html)
I can use JS to open the above link, but in that case, the URL is visible in the address bar. I am trying to open the above line in the iframe. But it seems my secondary chrome extension is blocking the main extension url. I have added the URL in content_security_policy also.
<body>
<iframe src="chrome-extension://hclbghnhiklgejahckgmpldjgfgleofc/index.html"></iframe>
</body>

Related

can the popup of an extension access html of the open tab using content_script or executeScript on about:blank pages?

I'd like to use the popup of an extension to set settings that make changes on about:blank pages html one is on (from Google Slide Presenter in a separate tab), in terms of how the extension is supposed to behave on that page.
As far I understood I need to use content_scripts due to about:blank which requires "match_about_blank" : true as otherwise I have not way to run javascript on that page via the extension, unless there is a way using executeScript?
Is it possible from within the popup to access the HTML of that open tab using content_script?
I.e. I'd like to retrieve the tabs page title, i.e. using document.title or extract from the HTML. Also with Javascript I'd like to change some of the content within a div.
The only workaround I can think of, unless its the only way, is to run javascript on the page to extract and store the value (chrome.storage.sync.set) so I can retrieve it in the popup with javascript (chrome.storage.sync.get).
Wondering if there is a better way directly and also how to change content in the tab i.e. by clicking a button in the popup (maybe via event listener on the tab and a push from the popup?).
I already tried the answer using chrome.scripting.executeScript. with Manifest v3 but couldn't make it work. How to access the webpage DOM/HTML from an extension popup or background script?

Chrome extension - Make injected element open a html page contained within the extension

I'm developing a chrome extension and I want to inject an tag into an object, then make that tag take you to an about page, stored inside of the extention itself. Is there any way to do this? Here is my content.js file:
var text = document.createElement("a");
text.appendChild(document.createTextNode("About BSR"))
var yourDIV = document.getElementsByClassName("www-user-info")[0];
yourDIV.appendChild(text);
Thanks!
Chrome extensions recognise the custom html templates for the extension popup menu and the options page, but I'm not sure if you're allowed to define templates which can be navigated via anchor tags / href.
One solution is to add code to either popup.js or the content.js to open a modal window in the current window and show the "about" information for the extension.
I've used a similar approach for an extension I'm currently working on.

How to open a browser app which is listed in chrome://apps

Chromium-based browser has the apps page at chrome://apps
There are some apps that I have installed into it. Is it able to launch one of them from JavaScript somewhat just like opening file selecting box?
I can open chrome://apps by setting this URL in to a link, but how about a single app?
Copied from: Open Chrome in a new window (Chrome app)
Sadly, there's no way to do that I know of.
Using window.open in an app's context is a bit of a hack, but results in the URL being open in the user's default browser (not necessarily Chrome). There's no control as to how the browser chooses to open it.
There's a Chrome App-specific API that was created specifically with "open a page in Chrome" in mind, chrome.browser. However, it still doesn't provide an option to open in a new window.
The closest you can get is to create your own "browser": an app window with an in it. Then you have full control over the presentation, but it's not integrated with Chrome's profile and may require additional work to implement things like dialogs and browser controls. See the Browser sample app and documentation.
You may need the app id which you can then append to the URL. I am not entirely sure how you would find but if you go to the apps page on chrome, drag the icon of the app to the search bar in the browser, you should get the full link.
For instance, I dragged the Google Slides Icon onto the search bar and it gave me this url chrome-extension://aapocclcgogkmnckokdopfmhonfmgoek/main.html. So, you may give it a shot! Try to open the chrome apps page, then drag the app you want to open in new tab onto the search bar.
Hence, using Javascript:
window.open("chrome-extension://aapocclcgogkmnckokdopfmhonfmgoek/main.html", "_blank");
Opens Google Slides App in a new tab.

Chrome Extension: If my app does not have a default_popup set then I am not able to view Inspect Popup. How to debug?

If my Google Chrome extension does not have a default_popup as I need to use chrome.browserAction.onClicked.addListenerwhich is not called if the property 'default_popup' is set in mainfest.json file.
Problem
As shown in screen shot given below the inspect popup is disabled which is the key to open the dev. console for the extension.
How to debug?
Open the Extensions page of Chrome (chrome://extensions/), and enable developer mode if you haven't done so already. Click the link next to "Inspect views" to inspect your extension's background page.
Note that your extension's background page is not the same thing as its popup. Inspecting the popup and the background page of an extension that has both will give you two completely different inspectors!
Each html page your extension loads needs a separate devtools instance.
You can find all inspectable views at "chrome://inspect"
If you want to break on uncaught exceptions and the devtools are not opened yet, you can use a function wait_for_devtools to delay your startup function (e.g. after window.onload or document ready)

Google Chrome Extension

How do I open a link in a new tab in the extension HTML.
E.g.
clicks on icon
sees Google chrome window which has the window.html
inside there are two links, one link to open a link in a new tab, other in the original tab.
I used window.location, doesn't work like that.
If the page is indeed in a google chrome extension, you can force the browser to open the page in a new tab using javascript (which you know is enabled sine you are a google chrome extension).
chrome.tabs.create({url:"http://somewhere", selected:true});
Your extension will need the tabs permission.
See: http://code.google.com/chrome/extensions/tabs.html
I don't know why this question has two upvotes, but anyway you can try using the target attribute for anchor elements.
<a target="_blank" src="http://myFancyUrl">This is a link to a new tab</a>
However, it won't open in a new tab unless the user has the navigator configured that way (usually does).

Categories