Chrome Extension: Open window when running in background - javascript

So, I have my chrome extension, runs in background fine. And every few hours it uses the notification API to ask the user a question.
If they click one answer we open a tab in the current window.
Problem: If there are no chrome windows open (i.e. the extension is running as part of "Let google chrome run in the background" option), the tab doesn't open.
Here's the code which works fine as long as there is at least a single chrome window open:
// tried this too: chrome.windows.create();
chrome.tabs.create({url: pathToGo});
How to make "chrome.windows.create()" actually make a window if there are none already open.

Use chrome.windows.getAll(object getInfo, function callback) APIs to get all open windows.
If in the callback, the array of windows is empty, create a new window using chrome.windows.create(object createData, function callback).
Use chrome.notifications API if you are unable to create new window.
http://developer.chrome.com/extensions/notifications.html

Related

How to close a url/website/tab using google chrome add-on?

So, imagine a person opening an online gaming website(for example krunker.io) in chrome, and what I want to know is whether there is a way to detect if a url(in this case "https://krunker.io/*") is open and to immediately close the tab(or the browser) using a Google Chrome addon(or even an outside application is fine).
The window.close() method does not work, as the person him/herself is the one who opens the tab/window, not the application
To close a tab, you can use the chrome.tabs.remove method.
// retrieve the id of the tab to close
$tabToCloseId = retrieveIdOfTabToClose(); //To write by yourself
chrome.tabs.remove($tabToCloseId);

chrome extension - usage onChanged in background.js, content_script.js and iframe

I'm developing a chrome extension.
The scenario is as follows:
I use background.js that controls the notification settings of my extension.
Content_script.js, which captures information from the current window and inserts an iframe page of the same extension.
Frame_content.js: This is a tab that appears in the right part of the window and that when it is clicked it is displayed.
Example:
step 1
http://oi67.tinypic.com/kcm336.jpg
step 2
http://oi64.tinypic.com/28w1pp3.jpg
I am using chrome.storage.sync to communicate between bg.js , Content_script.js and Frame_content.js and display the tab depending on whether or not it is clicked.
My problem is that when using the listener chrome.storage.onChanged.addListener, it modifies the storage of all chrome windows and open all tabs. I need it to work ONLY in the current window.
That is, when I click on the tab it is displayed in all the browser windows and when I do it small happens the same.
¿Any solution?

Why firefox open a new window for downloading jnlp file

I have a javascript application that runs in firefox. At some point, I have to start a java application, so I created a jnlp file for it. I have a button that execute some javascript code and then call
window.open('GetJnlpApplication','_blank');
On Chrome, IE, Edge and even Firefox on Linux, this work as excepted: the browser download the jnlp file and run javaws while user remain in the application shown in browser window.
On firefox on Windows (all versions I tried: from 45 onward) a new tab is opened, then javaws is correctly run, but the browser remain on the new blank tab. Please note that IE (and FF on Linux) quickly open a new tab, download jnlp file and close the new tab.
Question is: how do I make firefox immediately close that tab?
Final note: I use target _blank because otherwise firefox would trigger and WindowClosing event when calling window.open(), and this would logout my application.
Post scriptum: I tried without the _blank argument and nothing changed: firefox still open a new tab and keep it opened.

How to close the window on the latest version of Mozilla Firefox?

I am currently using Mozilla Firefox 30.0 and it seems that it doesn't support window.close() anymore.
You may refer on the image below or if it is too small for you, here is the
link.
I opened the website of Google using window.open and then I tried to close it using window.close() but it says undefined.
Is there any other option that I can using to close the window using javascript on firefox?
The Firebug console unfortunately does not display the warning that goes along with it, which reads (in the regular Firefox Web Console}:
Scripts may not close windows that were not opened by script.
Also MDN window.close states:
This method is only allowed to be called for windows that were opened by a script using the window.open method.
So, you aren't allowed to call window.close() on windows that were explicitly opened by the user.
PS: This isn't new behavior, but around for ages (even before Firefox was called Firefox).
PS: To give an example, you are allowed to do something like this, only, i.e. close a window returned from window.open:
var w = window.open("http://google.com");
setTimeout(function() { w.close(); }, 1000);

resizeTo() not working in Firefox

Running Firefox 12.0. I'm just starting to write a app that I want to run on localhost. I want it to open it in a (600,400) window, but since I have Firefox set to open everything in tabs I thought I could bookmark it and right-click to open it in a new window.
$(document).ready(function() {
window.resizeTo(600,400);
});
Doesn't work. Is what I am trying to do possible?
Thanks, Jim
This isn't possible, unless the window was opened through javascript using window.open and has only 1 tab in it.
Since Firefox 7, it's no longer possible for a web site to change the default size of a window in a browser, according to the following rules:
- You can't resize a window or tab that wasn’t created by window.open.
- You can't resize a window or tab when it’s in a window with more than one tab.
MDN docs

Categories

Resources