Is there a chrome extension callback to detect when an extension is restarted or the browser is closed?
I see chrome.runtime.onSuspend but can not get that to be called.
Is there a chrome extension callback to detect when an extension is restarted
Yes, chrome.runtime.onStartup will fire when the extension is loaded for any reason, e.g. the browser is started or the extension is restarted.
or the browser is closed?
No, you don't get any event in this case. Chrome won't wait for extensions if the last window of the browser is requested to close.
chrome.runtime.onSuspend is only for the non-persistent event pages unloading while the browser continues to run.
Related
Is there a way to debug nightwatch even within the command chains, or debug the injected code in chrome DevTools?
For instance, I want to debug the "window" object:
I use chrome Version 59.0.3071.115.
According to ChromeDriver - WebDriver for Chrome the DevTools is always disconnected from ChromeDriver as soon as the DevTools opens. Meaning, if I inject the code within the execute command (images) the DevTools will close and I have to reopen it again? Meaning, I cannot even debug it in the front end?
Thanks!
Apparently, the only way to debug or set breakpoints within the command queue is by means of callbacks, as shown in the following example.
Setting a breakpoint to inspect a page in browser
Sometimes it is important to inspect a page in browser in the middle
of a test case run. For example, to verify used selectors. To pause
execution at the right moment set a breakpoint inside a callback:
browser.perform(function () {
console.log('dummy statement'); // install a breakpoint here });
The example where taken from https://github.com/nightwatchjs/nightwatch/wiki/Understanding-the-Command-Queue.
Except:
Except for the execute command, because nightwatch injects the specified script directly into the browser, which will be executed right there. Moreover, chrome only allows one DevTools per page, hence it will try to reopen the DevTools each time a command must be executed.
DevTools window keeps closing
This is normal.
When you open the DevTools window, ChromeDriver is automatically
disconnected. When ChromeDriver receives a command, if disconnected,
it will attempt to close the DevTools window and reconnect.
Chrome's DevTools only allows one debugger per page. As of 2.x,
ChromeDriver is now a DevTools debugging client. Previous versions of
ChromeDriver used a different automation API that is no longer
supported in Chrome 29.
If you need to inspect something in DevTools, the best you can do now
is pause your test so that ChromeDriver won't close DevTools. When you
are done inspecting things in Chrome, you can unpause your test and
ChromeDriver will close the window and continue.
Source: https://sites.google.com/a/chromium.org/chromedriver/help/devtools-window-keeps-closing
I have developed customize browser using IE WebBrowser Control in c++. Everything works fine. The only problem I am facing is when I am closing the browser. It closes normally if there is no to-and-fro of data happening like in light-weight website. But it hangs/freezes while closing if there is to-and-fro of data happening like audio player is running on the website or in a real-time update website where it keeps sending and receiving the data.
I am doing the clean closing and destroying of the browser as mentioned here. I also tried to navigate to about:blank before closing. Still nothing.
From the call stack I could see that it is still trying to run some JavaScript code while closing/destroying the browser. I tried to look into it if any-how I could clear or stop all activities but still I found nothing.
Any suggestions?
Try this:
IWebBrowser2::ExecWB(OLECMDID_STOP, OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL)
I'm using the framework Meteor (Node.js).
I get this error message in my web browser when my project page is loaded:
The connection to ws://localhost:3000/sockjs/622/u2zaukpp/websocket was interrupted while the page was loading.
Why is it occuring?
It happens every single time you reload the page or it gets reloaded by the server.
Basically the page is constantly receiving data from the server (collections data, methods, or simply a ping). Since it is constantly open and Meteor forces a reload on code change (or you did force one by reloading the page), your browser freaks out and shows you this error.
It can also happen if the Meteor process is killed.
Thus, expect to see this error a lot during development, you don't have to worry about it.
My team and I have created a Chrome Extension which bundles a PNaCl application to handle multimedia encoding & muxing which is adapted from the Pepper SDK (version 39) examples and the online SDK tutorial. The application's purpose to capture content from the user's desktop, tab, and webcam in order to create multimedia files.
The extension works as expected while it's visible but the PNaCl process is stopped/unloaded when the extension is hidden. I need to know what is the best strategy to persist a PNaCl process when the Chrome Extension is no longer visible.
The PNaCl app is embedded in my primary UI code (in my case this is set to index.html). The extension contains Background Pages which continues to process requests when hidden so I'm confident the manifest.json permissions and process work as expected. Additionally there are no exceptions.
So far I've attempted:
Make a background JavaScript page the interface to the PNaCl application so it's reference is stored in the background page which should persist.
Create a Chrome Window in order to persist PNaCl application and present a live-preview of the captured stream while the extension is hidden.
(Ongoing) Embed the PNaCl container a background HTML page rather primary HTML page which represents the extension UI.
So far none of them have persisted the PNaCl process.
The relevant parts of my manifest.json:
{
"manifest_version": 2,
"minimum_chrome_version": "39.0.0.0",
"offline_enabled": true,
"permissions":[
"desktopCapture",
"tabCapture",
"tabs",
"unlimitedStorage"
],
"browser_action":{
"default_popup": "index.html"
},
"background":{
"scripts": ["helpers.js", "background.js", "capture_state.js"],
"persistent": true
}
}
If I'm able to resolve before I get a response I'll respond with a solution.
We've resolved the issue despite the lack of documentation.
Here are the primary issues:
Issue #1 - Listener ID in front-end extension code.
We had our id="listener" inside of our front-end extension code (which is unloaded when the extension is hidden) and manually specifying a background.html page doesn't allow us to use background JavaScript files (a requirement of our application).
Resolution: We dynamically added the id="listener" and altered the common.js file using document.addElement to the generated background page (which is automatically created when the extension is loaded).
Issue #2 - getUserMedia method invoked in front-end extension code.
Our application requires that the streams returned from getUserMedia persist so that we can capture from the mic, webcam, and desktop in the background even if the extension is hidden.
Since we requested these in the front-end extension code (to create a live-preview) we thought we could simply pass them into the generated background page and they would persist.
What we found is that when the extension is hidden reading from the streams halts immediately without error. We found this out by digging through our code and monitoring the Chrome Task Manager to see that when the extension was hidden it's CPU usage goes to 0 but it's memory stays elevated (much like phenomena you'd expect when a thread deadlocks or is blocking).
Resolution: Moving the getUserMedia invocation to one of the background scripts and using the streams it returns resolves this.
If you create the PNaCl object in the popup window, which is supposed to be a throwaway destroyed whenever it loses focus, you won't be able to persist it.
It's not losing visibility, it's just completely unloaded.
Your "Ongoing" idea of putting the <embed> into the background page is probably correct.
I am having an application where there will be lots of ajax calls and jquery load functions etc.I found that dynamic content is not loaded correctly every time i open the page due to browser history,if i delete the history and refresh the page its working fine.now
is there any way to clean up the history of the browser?(is this method correct?)
Can i prevent the page from being cached????using any jquery code.so that my application wont be stored in browsers history.
you need to set cache to false in your jquery ajax settings
see here