Access userscript variables from the Google Chrome console

For debugging purposes, is it possible to access userscript variables from the console in Google Chrome?

+5
source share
3 answers

Suppose you have a Chrome account with this code:

var userscriptVar = "I'm a global variable, userscript context.";
window.var2       = "I'm a window.scope variable, userscript context.";

console.log ("Hello from the userscript.");


To access these usercript variables:

  • Define the user ID. You can see it on the extensions page ( chrome://extensions/):

    Getting script id

  • Go to the script context by clicking the context menu at the bottom of the console:

    Switch to custom field area

    Please note that the identifier ( pfnbaeafniclcjhfkndoploalomdmgkc) matches the identifier specified on the extensions page.

  • (var2), usercript (userscriptVar), script -nstance .

    Access script vars after script done

  • usercript, script - , script . , , . .

    ( )
    Userscript paused at a breakpoint

  • , , , .

    ( )
    Can't change from console

  • :

    (, )
    Setting value

+2

. var enter ( dir(xxx) )

NB: var global unsafeWindow

+1

, global.

var x = "Chairman Mao";  // x not accessible to chrome
    x = "Chairman Mao";  // X becomes accessible to chrome via inspector
0

All Articles