How can I save a custom javascript function so that I can use it anytime on Chrome console even after I reboot Windows?
CodePudding user response:
In the developer console, you can go to the Sources tab, and then to the Snippets subtab. Press New snippet and then type in the code you want and save it.
You can now open and run the snippet whenever you want by right clicking on it and pressing Run.
If this is a function you'd want to run when going to a certain page or website, you might consider using a userscript instead - they're much more flexible for running your own custom JavaScript on pages, and can run automatically on pageload, or on the click of a button, and so on.
CodePudding user response:
The simple soution to this is to use local Storage here as asked it helps to keep a record untill user itself don't flushes out the client's local Storage what you can do just open inspect elements and open Storage tab . Then there you need to open the add (plus symbol in the local Storage section ). So this section act as a storage section (small storage section upto 4MB (need o verify )) so what can be done here. You can add your function here by converting into an object as it stores only strings so need to convert that object into an String before putting . for this stringify method could also be used. To set values inside locl Storage :- Once can use => localStorage.setItem('Inside ypur string that ypu want to set'); To fetch you can you use in the console or from your JS file => localStorage.getItem('name of your key') Basically localStorage keeps/store like it key-value pairs but in pairs Okay. Here we can use it like parse Method for this if needed to convert back to String . So now just checkour localStorage yourself your issue will be resolved .