Alert in Google Script editor - javascript

I am making some quick scripts to manipulate spreadsheets in my Google Drive. However I want to avoid the script accidentally running and modifying data before I know it works, or running additional times after it has done its job. Thus I would like to have a popup button/alert in the Google Script editor where the user (typically me) confirms that they want to continue running.
I have tried things such as getUi().alert(), but it seems to be more used when I distribute the script as an app. Any hints?

You cannot get alerts inside the Apps Script editor.
An option is that you add the debugger; statement in your code and then run the script in debug mode (Go to Run > Debug Function > function name).
The execution will automatically pause at places where the debugger statement exists.

Related

using importScript in chrome extension web page scripts

In my chrome extension, I'm using a v3 manifest. It starts a background script which starts the extension's page (extension.html) in the browser. The page also has a service script (extension.js) which handles things happening on that page. Extension.js is started from the last line of the HTML body. All of this seems to be working fine.
I've tried to encapsulate the complicated portions of the code into relevant function blocks (and seperate files), which are then called as functions from the main code stream. These functions get pulled into the background.js using importScripts('function.js'); - and this works great.
In the page's service script (extension.js), attempting to do the same importScripts('function.js'); results in Uncaught ReferenceError: importScripts is not defined,
Shouldn't this functionality work the same in both the background.js and extension.js scripts?
I've tried the various wrappers and permutations found in other similar questions. Since these are not really 'worker' scripts, those suggestions simply result in the importScript not being called.
Thanks!

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

Is it possible to make the chrome snippet auto run?

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.

VS2012 and JavaScript issue

I try to debug my JavaScript but the issue is more about VS2012. When I run the website debugger it creates some dynamic pieces of code which you can study while debugging but all the JavaScript code doesn't update once I run the debugger. In short it runs the same JavaScript code as the first time I saved the respective document containing the current code. It seems to me like a pretty huge bug, and therefore it also encouraged me to investigate it through the internet but I seem to be the only one to experience it.
I think that's because you're trying to change the dynamic scripts. It doesn't work...
Instead of that, you should edit your source files and save them. If you do so, you don't need to stop the debugging process and start it again.
Just do edits in the source files and save them, then refresh your running page in browser and it works...

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.

Categories