Running code snippets from Google Chrome console command line, using (experimental) code snippets feature?

前端 未结 2 1809
野性不改
野性不改 2021-02-01 03:37

Reference:

Using the new code snippets feature in google chrome

I am using the code snippets in google chrome, so say I have a snippet file. check_consistency.js

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-01 04:04

    I have a work around for when I'm running snippets a bunch of times on a site. I wrap my snippet code in a function and assign it to a global variable.

    e.g.,

    window.mySnippet = function (value) {
      console.log(value.toUpperCase());
    };
    

    When I run this snippet I can now run

    mySnippet('hello world');  
    -> "HELLO WORLD"
    

    You still have to run the snippet once to load it into memory, but it's better than nothing.

提交回复
热议问题