onInstalled chrome runtime debugging? - javascript

chrome.runtime.onInstalled.addListener(function(){
chrome.tabs.update(null, {url: ''});
alert();
});
Above code doesn't work when I install my extension in developer mode. I want to update the active tab to be a blank tab once my extension installed in chrome web store.

That's an invalid URL, that's why it does not work.
You can't just "erase" the URL without navigating to what you supply as the new URL.
If you are trying to navigate to the New Tab page, it has a URL (that's normally hidden) chrome://newtab. If you want a blank page in terms of content, it's about:blank.

Related

Failed to load URL because the scheme does not have a registered handler, using extension URL

I'm trying to use window.open to open an extension page, I don't care about checking if the user has the extension, I just want to open a window that starts with extension://, it's not working and says failed to load url because the scheme does not have a registered handler. My code looks like this:
const openedWindow = window.open("extension://<extension url>", "", "width=300, height=300");
openedWindow.onload = () => {
openedWindow.close();
}
this code works with normal urls, but not with ones starting with extension://. Is there any way to open a url like this?
edit: needed to use chrome-extension:// instead of just extension. Now there's a new problem, chrome is blocking the page. How do I fix this?
It's because the correct URL for a chrome extension is chrome-extension://1234
Also popups should be explicitly allowed by a user interaction on the popup permission that Chrome asks in the URL bar

how to make chrome extension with options that allow you to open settings of chrome in new tab?

today i'm facing problem that i can't solve my problem is very simple i wanted to make
chrome extension that allow me to do some easy steps exomple i wanted to open chrome setting
in new tab with my extension i did setting botton in the extension and the clear browser data
and open extension of chrome but when i try to open it when i click nothing happen it keep
give me this error =
Not allowed to load local resource: chrome://settings/
and my code is this =
<div class="flex"><i class="fas fa-cogs" style="color:darksalmon "></i></div>
please help me to solve this error please and thank you very much
You cannot use the standard HTML anchor to open an internal Chrome link. Chrome’s links are not valid navigation protocols, only these are:
Website
Email
Telephone
Document Section
JavaScript
For a internal Chrome link you should open a new tab and pass the internal link to it via the Tab API...
https://developer.chrome.com/extensions/tabs
Use the function "create"...
chrome.tabs.create({'url':'chrome://settings/','selected':true}, function(tab){
/// Whatever else goes in here...
});

How to open a tab to a file:/// URL Firefox extension developement?

I don't know much about JavaScript. I am trying to open a tab with a file URL and it keeps reverting to the about:newtab page. Is it possible to open a file URL in Firefox extension?
Currently I am using:
var updating = browser.tabs.update(tab.id, { url: result.data.url });
updating.then(onUpdated, onError);
Where result.data.url is a file URL. It works with HTTP and HTTPS URL.
I am using Firefox 56.0.1
Currently it's not possible. You can follow bug https://bugzilla.mozilla.org/show_bug.cgi?id=1266960 to stay up to date.

Clear the Omnibox from Chrome extension code

I've written a Chrome extension that replaces the new tab if the user wants that. It works by intercepting tabs.onUpdated and redirecting chrome://newtab/ to another page from the extension, as described in this answer.
The problem is that the address bar of that page keeps the (ugly) URL of the HTML within the extension, e.g. chrome-extension://hibkhcnpkakjniplpfblaoikiggkopka/html/newtabl.html. How can that URL be replaced with the empty string?
I've tried history.replaceState, but the best that can do is to change the file (newtab.html) in the path. Using an http:// URL crashes the extension:
history.replaceState({}, 'iDoRecall practice', 'http://type-anything-here.com');
Any clever way to clear the Omnibox?
Put simply, History API can only change the path part of the URL, not the origin (protocol://host:port) for an obvious reason of preventing site fraud:
If the origin of the resulting absolute URL is not the same as the origin of the responsible document specified by the entry settings object, and either the path or query components of the two parsed URLs compared in the previous step differ, throw a SecurityError exception and abort these steps. (This prevents sandboxed content from spoofing other pages on the same origin.)
The omnibox may be empty only in one case: on a new tab page, that is you'll have to replace the new tab in manifest.json in chrome_url_overrides.

is window.open("", ... impossible with firefox?

In firefox I have opened a locally stored file with the file:// protocol
(file:///c:/temp/foo.html)
foo.html contains Java Script which (among others) is supposed a new
window without URL:
var new_window = window.open("","", "height=100,left=50,width=200");
When this line is reached, Firefox displays this "Firefox prevented this site from opening a pop-up window". I don't understand why Firefox gives this warning, obviously, the file (foo.html) is under my control (since it's stored locally and I have opened it with the file:// protocol, and, additionally, the window to be opened doesn't point to any file that could contain any sensitive data, as the url parameter in the open method is set to "".
But besides all this, it seems I can't even force or allow firefox to open the window anyway. There's this "options" button on the yellow "Firefox prev...." bar which supposedly should allow to create exceptions, yet I can't.
So, the question basically boils down to: how can I allow a local html file to open an empty window with Javascript within Firefox.
Thanks / Rene
This is a Firefox security precaution, see this link:
http://kb.mozillazine.org/Links_to_local_pages_don't_work
However, it looks like this extension will allow you to override it:
https://addons.mozilla.org/en-US/firefox/addon/281
This is the popup blocker, which block popups not opened by an explicit user action like a click.
You cannot force it to open the popup, you need to allow Firefox to open it.
I suggest you to test the new_window variable to see if it is null. In this case, display a message to the user so that he allows the domain to open popup windows.

Categories