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?
Related
I have a chrome extension which has a persistent background page in order to stream audio even when the user closes chrome. What I would like is to implement an option for the user to disable audio streaming after chrome has been closed. Right now I am detecting when all chrome windows have been closed and pausing audio, however chrome remains 'open' in the task manager and system tray (note that running in background chrome setting is enabled). This stops audio playback but the chrome process remains open in task manger and the icon remains in the system tray. By contrast if I completely disable the extension and then close chrome, the application closes completely and no system tray icon remains.
This Question suggests that only a user can explicitly close chrome if there is a persistent background page, My goal isn't to close chrome explicitly but simply prevent MY extension from being the one keeping chrome open (depending on user specified options), therefore an event page doesn't seem to be a good fit.
Is there a function call or some other programmatic way I can close my persistent background page once all windows have been closed, if that option has been enabled? Or am I stuck with the chrome application staying open because the background page is persistent?
I've found an answer to my own question so I'll post it here. In order to have a background page you do not need the "Background" permission declared in your manifest. This permission is what allows the extension to stay open after chrome has closed (and potentially open before chrome?) rather than being necessary to have a background page. So a persistent background page will close with chrome if this permission is not set, and will stay open even after chrome is closed if it is set.
Bearing this in mind, the solution for me was to set the "background" permission to optional, and enable it if I wanted my extension to stay open after close, then remove the permission if I didn't want it staying open after close (the user now has an option to toggle this).
In a web application, I have an optional popup window into which logging content is being loaded. This window is opened via Javascript using window.open().
The users typically have multiple tabs of the application open and my intention is to always reuse the same popup window (if currently open), no matter from which tab they trigger the popup. To do so, I use code similar to this to open the popup:
<script>
function myFunction() {
var myWindow = window.open("popup.html", "my_popup", "width=600,height=400,status,resizable");
}
</script>
This works fine in Firefox and IE - only a single popup window is ever opened and all content that I want to log is being loaded into that window.
Chrome and Safari however, use different popup windows depending on the tab from which the popup is launched.
I assumed that the second parameter of window.open() specifies a target name from a global namespace, which seems to be the case for most browsers. But Chrome and Safari behave as if there were tab-specific namespaces for these target names, i.e. "my_popup" referenced from tab 1 refers to a different target than "my_popup" from tab 2. (to make things more complicated, tabs that have been "duplicated" seem to share the same namespace, i.e. they do reuse the same popup window, but tabs created otherwise don't.)
Is there a way to circumvent this behavior of Chrome and Safari and access the same popup window from all tabs that the user may have open?
Or do I have to assume that this is browser-specific behavior for which there seems to be no workaround?
I have tested this with various browsers:
IE 11.0.9600.18204
All tabs with content from the same domain open/reload a single shared popup window (i.e the target namespace seems to be local per domain).
All tabs with content from file:// URLs reuse the same popup window as tabs with content from http:// URLs that point to the local intranet.
Firefox 46.0.1
All tabs with content from the same domain open/reload a single shared popup window (i.e the target namespace seems to be local per domain).
All tabs with content from file:// URLs use their own single shared popup window (i.e. file:// URLs seem to have their own target namespace).
Edge 20.10240.16384.0
The behavior is inconsistent: in most of my tests, Edge behaved like Firefox, but occasionally like Chrome as well.
I don't have a problem in ignoring Edge for the time being.
Chrome 50.0.2661.94
Each tab opens or reloads its own popup window (i.e the target namespace seems to be local per tab)
Safari 9.1
Each tab opens or reloads its own popup window (i.e the target namespace seems to be local per tab)
By the way, in all of these browsers the behavior does not depend on whether or not the popup window was launched due to user interaction: the behavior is identical between cases where the popup is launched via body onload() and cases where it is loaded via button onclick().
[here's additional background information that I assume not to be relevant to the problem, but who knows... ;-)
Actually, our application does not directly open the popup windows, instead we're using log4javascript which opens a logging window (or in case of Chrome: multiple logging windows). I'm willing to extend the log4javascript code to deal with this and send a patch to the maintainer, but in order to do so I need to solve the basic problem described above]
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
I'm developing a tool that lets you open multiple pages at once with a shortcut, to be used for things like opening your daily sites or querying multiple search engines for a phrase. In Firefox, Internet Explorer and Opera, assuming you've unblocked pop-ups for the domain, the code works as expected.
Chrome, however, opens the sites in new windows instead of tabs if the links are opened automatically when the page loads. If openAll() is commented out and the button is clicked or a key is pressed, the pages open in tabs. Note it's calling the exact same function.
The best solution I've found (which isn't saying much) is the One Window extension. It works, but you can see the new window open then get sucked back in, and it keeps you from opening new Windows with Ctrl-N, forcing you to drag tabs out to use another Chrome window.
I can understand there not being a programmatic way to change this because it's a browser setting, but as a user of the tool it's annoying to have the sites all open in new windows. Is there a Chrome setting or extension that will open links in tabs when they're loaded without user input? I realize opening a bevy of windows is the very thing browsers aim to stop, but this is one time where I want to allow it.
<input id="openAllBtn" type="button" value="Open all links"> (Or press any key)
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.min.js"></script>
<script type="text/javascript">
function openAll() {
window.open('http://yahoo.com/');
window.location.replace('http://www.bing.com/');
return false;
}
$(document).ready(function() {
$(document).bind('keypress', openAll);
$("#openAllBtn").bind("click", openAll);
openAll();
});
</script>
Here's a Fiddle of the code: http://jsfiddle.net/sfzjR/
Is there a Chrome setting or extension
that will open links in tabs when
they're loaded without user input?
Check out the create method in the chrome extension docs. By default it will open a new tab, you can optionally specify the window you want that tab to open in, and give the tab a url.
I'm attaching some functionality to javascript by doing a firefox addon. However when coding in chrome and listening to the load event in the chrome overlay triggers for every loaded tab, but the "content" variable only points to the tab currently in the foreground.
How can I get the content of every tab upon document load from a firefox addon?
Assuming you are using code like this to be told every time a new page loads (which is what you really want to use if you aren't), aEvent.originalTarget is a reference to the document that the event was for.