Is it possible to make the chrome snippet auto run? - javascript

I have created some javascript code which searches the DOM and exposes some information for myself in the console, but in order this to work every time I have to go to Sources part of the console, go to the snippets part, click on the snippet name and run it.
Is there a way to make it autorun? Thanks!

idk, been using "Custom JavaScript for websites" chrome extension:
https://chrome.google.com/webstore/detail/custom-javascript-for-web/poakhlngfciodnhlhhgnaaelnpjljija

nov 2019 : These are current Chrome Extensions that can run scripts on any page you want
Custom JavaScript for Websites 2 regular updates, very easy to use
TamperMonkey regular updates and Canary versions, loads of options thus less easy UX

From what I understand, currently, this is not possible. If you want to auto-run javascript on websites I recommend using something like Tampermonkey chrome extension. It allows you to inject your client's webpage with javascript that automatically runs.

I use Chrome feature "Event Listener Breakpoint > Script > Script First Statement" that places breakpoint before first line of each script.
I check it on ten reload the page and before first script execution the Chrome pauses. I run all the snippets and code I need then I remove the breakpoint and resume the page load.

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

Execute JS on all sites on page load

I need to execute JS code after loading all/specified pages in browser (i.e. predefined code). Which browsers and their plugins/component provide to implement it?
Manual way is open console (e.g. firebug) and execute. I want to do it automatically.
Not completely automated, but a Bookmarklet will let you run your JavaScript by clicking an item in your bookmark bar.
For complete automation locally in your browser (asuming Firefox since you mention Firebug) you should look for addons which solves your particular need. Grease Monkey for example is very useful.

How to include JavaScript on a website through a Firefox addon?

How is it possible to execute JavaScript code on a specific page through a Firefox addon. I know I can use Greasemonkey but since I'm porting one of my Chrome extension, I want it to have the exact same features. So my question is, is it possible to execute JavaScript through a Firefox addon as if that JavaScript was executed in the page itself.
I was able to work it out somehow but every time I open a new tab, it gets executed in that tab again. Someone please help me fix this problem. I also want to use jQuery with this.
I use firebug, and go through the console to manually execute JS functions for testing. Alternatively, if you have to insert a whole JS include file, check out Fiddler.

How to substitute a content of certain javascript reference with local script for debugging?

I need to debug jasvascript loaded by page. Loaded page are not locally placed.
Loaded js is packed. I want to substitute it with unpacked version.
Is there any tricks or browser options to make it?
It looks like Fiddler's AutoResponder tab will do this for you.
You say you want to replace the JS with the "unpacked" version--if you just want to insert line breaks so you can step through in a debugger, the Venkman debugger has a "Pretty Print" button which does that.
It sounds like you are asking for after the application is already deployed somewhere so this might not be as helpful.
If your application already goes through a regular build script or process for debug or at least for release then you could do it there. You could leave the Javascript files as the un-minified/optimized scripts and when building for debug it just copies them over, but for release it runs them through your minifier/optimizer first before copying them over.
I know that jQuery uses a Google Compiler to package the framework up, but there are other tools that just minify the code. Also it gives you a chance to run any kind of quality checking tools (such as JSLint) on your Javascript when you already have it as part of your build process.
Other then that the AutoResponder idea from above sounds promising.
You could use Charles Web Debugging Proxy to map the requested JS file to a local unpacked JS file (or any other location). It costs money, but you can use the trial for 30 minute periods.
Firebug is a really good Firefox extension that lets you manipulate the DOM and you can see the changes as they happen. This will let you insert <script> tags to the page.
Just Edit the <head> piece of html through Firebug and insert the <script src="http://site.com/unpacked.js"></script> somewhere in the page.

Is there any way to have some javascript (such as a Bookmarklet) autorun on page load?

To execute bookmarklet code the bookmarklet needs to be actioned by the user. Is there any way to have a bookmarklet or indeed any javascript run automatically on page load?
Or is an Add-on the way to go?
Thanks
I don't think that it is possible to autorun a bookmarklet on pageload. This could be used very maliciously.
I think a plugin is the best way to go here. If only for personal use, you should check out greasemonkey for Firefox.
GreaseMonkey
Greasemonkey, or Tampermonkey on Chrome allow this.... but they need the script you want to run
for example, if a certain site always puts up some type of an ad overlay and you can find or write a script to kill that, you can enter that source into Tampermonkey and it will run on each page load globally or at whatever site / domain/ wildcard expression you designate
alternatively if you are looking to block certain scripts and want to automate the process, Notscript for chrome will show you each script that ran when you visited a site and allow you to designate which you want to allow on subsequent visits at that site or all sites, very very cool... that way you need not write or find a script to block behaviors you don't like
as previously pointed out, when you do this stuff you are seriously screwing with browser security, so be careful and just don't set up any old script unless you can read them or trust the source....
I think Opera allows you to auto inject js into a library of sites you specificy 'onload' regardless of ownership.
Well, any javascript runs automatically using onload event, if thats what you need?

Categories