Perform action before Chrome closes itself - javascript

I'm working on Chrome extension which needs to perform an action just before Chrome closes. Is there any method like chrome.window.onClose.addListener(...), or chrome.runtime.onClose.addListener(...) to ensure that something will be done and then chrome will close itself?
I've been struggling with this problem for two weeks. Here are the options for potential solutions that I've found, but they didn't work.
My investigation results:
Using function: chrome.runtime.onSuspend.addListener(...) - I don't know why, but it doesn't work at all for me. For example, I've tried to write a callback for this event, which tries to add hardcoded data to the indexed DB, but it doesn't add it. Description of this method even says that the callback is not guaranteed to be completed. OnSuspend documentation
Sent to the event page just before it is unloaded. This gives the extension opportunity to do some cleanup. Note that since the page is unloading, any asynchronous operations started while handling this event are not guaranteed to complete.
Chrome working in a background - with this option my extensions seems to work, but... only on Windows older than Windows 10. I've checked few options and on my other computer, which has Windows 7 installed, processes connected to Chrome are closing more slowly, which gives time for my extension to perform necessary tasks. Unfortunately, Windows 10 kills all the processes much faster. I've check option "continue running background apps when google chrome is closed", but it doesn't change anything. I've also enabled flag "#enable-push-api-background-mode", it hasn't helped either.
Keep Chrome running in the background on Win10, Enable flag to keep Chrome processes running
chrome.app.window.current().onClosed - I've found a similar question on Stack Overflow, and one of the answers was the code mentioned above. The problem is when I try to type chrome.app.win... inside console, it doesn't show any suggestions both in background script and content script. Google's documentation doesn't mention any permission that I've to add inside my manifest.json to get access to this functionality.Stack Overflow similar question, Google's documentation about chrome.app
Methods build in web browser - I've thought that method window.onclose might be useful in my case. I've performed the same test as for chrome.runtime.onSuspend, but the result was exactly the same. Documentation
I've stuck and haven't got any idea how to solve my problem. Maybe I missed something important? Hope you will help me.

Related

Can a browser's dev console continue executing JavaSript after a new page loads?

I'm trying to automate some online work through JavaScript and the Firefox (or Chrome) dev console. The work is mostly inputting the same (or similar) data on the same exact pages for many many people.
Example:
unique id
date 1 and 2
some more numbers
I wrote a very simple script that runs in the console and enters the data just fine.
The Problem
My script stops execution whenever it requires the page to reload or it loads another page. I cannot find any information on how to continue executing a script after a page has loaded.
My Limitations
I'm basically limited to what's on FireFox, Chrome, or Edge. Unfortunately, I cannot download any programs or tools that would make the automation any easier right now. Otherwise, I would just use Selenium and Python.
What I've Tried
First I tried to use the script that I describe above (simple DOM manipulation)
Then I tried to use the Selenium browser add-on, but I had to enter a starting URL for it to run. Selenium was not able to get past the login page of our system which is the only static URL that I can use as a starting point.
I then tried to use the Firefox Browser Console (different from the dev console) because the documentation seemed to suggest that I can use JavaScript on the entire browser (not just one tab). Unfortunately, I cannot find any helpful information on how to use the browser console for DOM manipulation. Everything that I search for points to how you create a browser extension, add-on, or how to use JavaScript on your own website.
What I Want To Do
I want to create a script that runs in a dev console. The script should take all of the data either from a separate page or an array then enter the data on each page for each person. I'll also have it prompt the user to verify the data before submission.
What I'm Looking For
What I'm hoping to get from this question is at least one three things.
An answer to the question's title.
Being directed to documentation or some other solution that can solve any of the above problems.
Being told if this is impossible and why by those who have more experience than me (I don't understand if the problem is just a lack of knowledge or limitations on the tools themselves.)
I think you can create a chrome extension and put your code in the background service worker. or use workers read this link

Running a test case on a webpage that is already open

I want to run my test cases via protractor, but due to some limitation I want protractor to start on a page that is already open, meaning I don't want driver to start by loading chrome and going to the url defined in test case. Is there any way if I can use the url that is already opened on screen and then process further with what is defined in the test case such as clicking on elements or sending keys etc.
Regards
Syed Zaidy
This feature is not implemented in selenium. It was requested but rejected because it is not feasible.
If you read the issue here, and scroll down to last comment :
I'm going to make a call on this one: it's a browser specific feature, and not something
that we can implement in a general way. With IE, it's possible to iterate over the
open windows in the OS and find the right IE process to attach to.
Firefox and Chrome, OTOH, need to be started in a specific mode and
configuration, which means that just attaching to a running instance
isn't technically possible.
Closing as "not feasible" here as this is a browser specific feature.

How to set callback onDisable chrome extension

I need help to create a callback when my chrome extension in disabled. I have already referred this link that says about adding a listener onDisable. But this doesnt work for own. When my extension is disabled, it does nothing. There is an answer in this link that says we can not do this, But I am still hoping that I can find something new on this topic. Please help me in this.
You are correct that management API cannot catch the extension itself being disabled or uninstalled. This is by design - you don't want extensions to be able to stop you from removing them.
There is no event you can process when either of those happen.
There is an exception in that your content scripts continue to run in an "orphaned" state and can detect that the parent extension is not there anymore by poking at Chrome API (and possibly onDisconnect event on a Port object), but at that point the content script can't do much.
Curiously, there is no event that will fire on enabling either. This can cause problems when an update happened while an extension was disabled and relies on runtime.onInstalled event to perform upgrades.

Website stopped working with Chrome version 32

I am the developer for a large enterprise website, after the upgrade to chrome 32 the website stopped working completely. I Get the 'aw snap' about the time we have to render most of the elements on the page.
Its a massive code base so i haven't been able to find what's causing it. Ive been booting chrome in debug mode and watching the logs there.
Wierd behavior:
1)If i disable flash it works, we are using swfobject with a flash library.
2)I sometimes see in the logs when it crashes "Uncaught RangeError: Maximum call stack size exceeded" so i must have a infinite loop, but its not a always thing.
3)If i refresh enough it will boot all the way up, and work for good until i kill tab and start over. But again thats a sometimes cause it may start the crash cycle again after a few refreshes.
4) I sometimes see the error "file_descriptor_set_posix.cc(22)] FileDescriptorSet destroyed with unconsumed descriptors" Which i think relates to a infinite loop in the rendering of the webpage which would relate to the maximum call stack exceeded error.
Does anyone know what has changed in Chrome Version 32 that would be a good starting place to find the bug?
Libraries used: SWFobject, Backbone, underscore, soundmanager.js
I dont know why this fixed it, or what chrome changed that caused the code to break but if anyone is interested in what we did to resolve the error i'll explain.
1) I made all events going out of swfobject and our swf code go directly to the Flash.js class we had to interface with flash. Before it was propagating through a Backbone.dispatcher to the flash class. That caused the aw snap error to go away.
2) We were using a datetime library called Moment.js version 2.2.0. It was the one throwing the maximum call stack error, after updating that to 2.3.0 it stopped. Would love to know what chrome changed to cause a infinite loop.
If anyone has info on what chrome changed between the two versions that caused either error, I would love the answer because its a bit scary fixing the symptoms but not knowing the cause.
chrome will open multi tasks in the task manager, and it is sensitive to many plugins
try the following
1- go to settings in chrome
2- open extentions
3- disable all the extensions that you can
4- close chrome
5- open task manager in windows
6- go to processes
7- close all the processes related to chrome
8- reopen chrome and check your problem again

Getting very strange javascript error and this page also refuses to work in Internet Explorer 7 or 8

This is the page I'm working on... http://schnell.dreamhosters.com/folio/earthquake.html
Its purpose is explained via the instructions on the left. I'm finding that after doing so many searches and clicking so many of the links in the list on the right that the page freezes up, the Google Map stops working and Firebug tells me of an error in main.js and it goes like this...
b is undefined
Line 49
I really don't know why this decided to happen all of a sudden and the error is so cryptic and muddled amongst Google's code that I don't think I'll be able to figure this one out by myself.
Another problem I'm finding is that the page itself simply refuses to work in IE7 and IE8 (or probably any version of IE for that matter). I am also at a loss as to how to solve this problem because I can't figure out how to use any of IE's debuggers (if they even have one) and seeing how I already tested this and made it work in two browsers (technically three since Safari runs off WebKit just like Chrome), I just don't have the drive or capacity to imagine what could be going wrong.
Any help would be greatly appreciated
Moved from comment to answer.
As scunliffe mentioned, you are trying to do a crossbrowser AJAX without using jsonp. Use either $.ajax() with datatype jsonp or add a &callback=? at the end of the URL in the $.getJSON() call.
IE8 is quite good when it comes to helping out the developer. From memory F12 will open up the developer window where you can inspect the DOM, CSS and debug script.
Your error is cryptic because most javascript comes minified, so variables are all remapped to single letters, etc. See if the script causing the problem has a development (i.e. unminified) version as this will make a lot more sense to step through.
With regards to your specific issue it sounds like a timing issue. While browsers do a decent job of executing script in a consistent way if you follow standards, they do differ in their timings i.e. when things execute. That would explain why b is undefined in some cases and not others.

Categories