Background / use case
I would like to automate some page interactions by pasting a script into my browser console (normally Chrome/Chromium or in my case IE11 because.. don't ask.)
Typical steps in one iteration:
(initial) Visit a page, wait until it is fully loaded.
Fill in form values automatically, trigger some buttons, submit.
Wait for new page after form submission.
Go to 'next page', wait until it is fully loaded, start over with a new set of form values.
The "Visit a page" or "Go to 'next page'" could either happen by clicking a button, or by setting document.location.href explicitly.
The "wait for ..." can take up to 30 seconds in both cases. Not for any good reason, just because.
I am aware (to my current understanding) that the js (event listeners etc) included in a page does not survive a new page load. I am specifically asking about js called form the browser's developer console.
Question
How can I register an event listener from the console for "page load complete" after setting document.location.href, or doing something equivalent?
As mentioned, in my use case I would need to do this with Internet Explorer 11. But I assume people are more familiar with the developer tools in Chromium or Firefox. Any answer that works in one of these browsers is welcome, just mention which browser you tried this with.
Limitations
I do not control the web application where I want to do this, I only control my browser. It also does not look like the developers of said application would be likely to respond to feature requests or wishes.
Perhaps someone will suggest to do this with an iframe. I am not sure this will work. If it does, this would be a different question.
Perhaps someone will suggest some kind of browser simulator tool to use instead of the console. Unfortunately I need/want to make this work on Internet Explorer in a corporate Windows environment with limited privileges. Alternative tools can be mentioned, but there is a reason why I focus on browser console.
Related
I'm experimenting with the Speech Synthesis API. I have the following code:
var message = new SpeechSynthesisUtterance("Hello");
window.speechSynthesis.speak(message);
The code works perfectly fine, however it only works when the user has clicked or interacted with the current page on the browser. I get the following warning on the Chrome console when attempting to run the code without interacting with the page first:
speechSynthesis.speak() without user activation is no longer allowed since M71, around December 2018. See https://www.chromestatus.com/feature/5687444770914304 for more details
I want the code to run as soon as a user loads the page without them having to interact with the page first.
I looked into simulating a page click with javascript/jquery like this:
$('#randomElementOnPage').trigger('click');
And then running the speech code, but it doesn't seem to trick the browser.
Any solutions/advice is appreciated.
Thanks.
EDIT: Since there doesn't seem to be any solutions, are there any browser/audio settings in Chrome, etc I can change for myself to allow this to work for myself only. Someone suggested going to chrome://settings/content/sound and adding the site to the list of allowed sites for audio. However, this does not seem to work either.
If, as it's said in your EDIT, you want to use your code on your own computer (computers in some way controlled by you), you may instead use some automation tool (and it will press buttons/interact with the page on your behalf).
I don't know what is trending now. Puppeteer or Intern or something like that, probably, will be an overkill (and puppeteer is headless, as far as I know). A long time ago, I personally, used AutoIt.
How can we detect through PHP or maybe in node.js or other languages if a web page crashed (without the browser EXITing) so that when a user press the "reload" button on the "Aw Snap" page in chrome certain specific content inside the page can be shown in this particular case (crash case).
In a crash without EXIT, a browser shows per example in Google Chrome the famous "Aw, Snap!" page.
I don't want to know how to capture if the user refreshed the page or the page reloaded which can be known quite easily with different methods [one example see this PHP this code which can detect if users refreshed the page on major desktop/mobile browsers except IE unfortunately this code does not capture a crash event and the fact that user might request again the same page after a crash.
I tried using "register_shutdown_function", and some other maneuvers using connection PHP functions like "connection_aborted" etc... but with no success. I figure out a sloppy way through the use of session variables but probably there are better clever manoeuvres.
Any help or suggestion would be greatly appreciated. Any solution in nodejs will be also welcomed.
web brower crash because too many process from your browser to PC of Client.
this crash can't detected by php because PHP server scripting. and you have question.., why not use JS for detect crash of browser?, because JS created just for controller website,. if you force to checked that use ajax, node, etc you can't do that, why? because the problem comes suddenly
and detected crash browser from php is impossible.
I need to implement a feature that checks for changed content before window close and display a predefined warning message if so.
What I did is simply register my handler as follows:
window.addEventListener("beforeunload", checkValueChanged, true);
In the very handler I initiate a synchronous request (using jsf.ajax.request()) to submit all pending data and calculate changes.
The whole solution seems to work pretty well for most cases, but when request takes a little bit longer (300ms?) the browser brutally kills the script without waiting for the response.
It happens only for Chrome (tested on 48.0.2564.116 m) - FF and IE waits for the request to complete. What`s more when I enable developer tools in Chrome it also works.
I suspect that this is an intended Chrome behavior based on a fixed timeout for onbeforeunload handlers execution time designed to protect user from various tricks and hacks on some sites (especially in porno ones :)).
My question is: have you ever encountered and handled somehow such situation? Is this "feature" documented somewhere in Chrome documentation or maybe its a bug? If its a feature can it be locally reconfigured or disabled?
I will be grateful for any hints :)
I think my topic clearly states my issue, but some more information:
This is for an internal application, so we have complete control over the user's workstation, can turn off pop-up blocking, etc.
They HAVE to start in Internet Explorer. I know Firefox has some good plugins for opening links in other browsers, but unfortunately they will not be starting in Firefox.
I'd prefer a solution that doesn't require the user to do anything but click the link in question, but if necessary some kind of right click -> select new browser solution (like some of the FireFox plugins I looked at have) would be ok.
We're currently writing all of our code in PHP / JavaScript / HTML.
You could use ActiveX.
In this case, all the user would have to do is to consent with a warning:
An ActiveX control on this page might be unsafe to interact with other parts of the page. Do you want to allow this interaction?
Also, the user would need to specific allow your page to run ActiveX scripts. (Allow in the security settings. It's not set by default)
If the user allows it, you can use the ActiveX Object WScript.shell, to run a command in the client's machine. Call the .exe of the target browser, passing the page to open as the first parameter (It works, at least in firefox and chrome):
//Works only if opening from IE:
document.querySelector("input").onclick = function() {
var objShell = new ActiveXObject("WScript.shell");
objShell.run('"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" "http://www.google.com/"');
};
<input type="button" value="Teste" />
Notice how Firebug can access the DOM of cross domain iframes and even allow you to modify them? I'm wondering if there is an firefox addon extension or a config setting that will allow a page on our intranet to do this.
Longer explanation:
I have a two "kiosks" in our reception area that the public can use. As we're running in kiosk mode (fullscreen, no chrome), I have created a small web application consisting of a menu and an IFRAME. The menu allows users to browse to approved sites and also perform actions like printing. It also gloms onto requests for popup windows and instead overlays them in a modal iframe rather than allowing the browser and OS chrome to be exposed - breaking the "kiosk" experience.
Obviously, this works perfectly on anything internal because it's all on the same domain. It gets trickier when browsing external sites because the XSS protection kicks in and you can't see the DOM inside the IFRAME.
I have also tried using a web-based proxy server on the same domain (PHProxy for example), which works okay, but there are horrible edge cases where it doesn't work - a big one is the CAPTCHA on our website forms. So that's pretty much not an option for me.
Basically I think the only solution that will work for me is to modify the browser in some way using a security setting or an addon. Any ideas?
Thanks guys very much for you time and consideration. It is VERY much appreciated.
--Iain
There is a way for unpriviledged JavaScript code (loaded from a web page) to request more privileges in Firefox. This is an old, non standard API that prompts the user for permission and if accepted allows the JavaScript to do things normal JavaScript cannot. One of these things is to bypass Same Origin Policy.
Sample code:
try {
// ask user for permission
netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');
} catch (e) {
// user refused permission
alert('Permission "UniversalBrowserRead" was denied.');
}
//Should now be capable of bypassing same origin policy if user accepted
Since the kiosk browser does not restart (I suppose) very often, the dialog just has to be accepted once. Not sure this is the most elegant solution but might work, at least for now (the API is old and might disappear).
Here is a link for more details: http://www.mozilla.org/projects/security/components/signed-scripts.html#privs-list
While looking for the exact privilege name I found this page about Security Policies in Firefox. This would be a much nicer solution. I have never used it, so I cannot give more info, but here is the link, might be a good place to start looking:
http://www.mozilla.org/projects/security/components/ConfigPolicy.html
Hope this helps!
I found an addon called CrossDomain. The addon hasn't yet been updated for newer versions of Firefox. In the end, I solved this whole problem by writing an HTA and using the internet explorer rendering engine - which made my IT manager happy :). Here is the link to CrossDomain in case this helps someone one day. Thank you everyone for your submissions.
https://addons.mozilla.org/en-US/firefox/addon/13004/
Why not use Greasemonkey, it will allow you to run your script on any page.