g_cmdstr = '' def _getCmdParam(): return g_cmdstr[1:] def _b_cmd(browser, tab, scriptmgr, params): filename = params[0].split(':')[0] line = int(params[0].split(':')[1]) url = scriptmgr.getUrl(filename) print(params, url) tab.call_method("Debugger.setBreakpointByUrl", lineNumber=line, url=url, columnNumber=0, condition='' ) def _bc_cmd(browser, tab, scriptmgr, params): filename = params[0].split(':')[0] line = int(params[0].split(':')[1]) url = scriptmgr.getUrl(filename) print(params, url) tab.call_method("Debugger.setBreakpointByUrl", lineNumber=line, url=url, columnNumber=0, condition='' ) def _bt_cmd(browser, tab, scriptmgr, params): scriptmgr.dumpStack() def _p_cmd(browser, tab, scriptmgr, params): tab.call_method("Debugger.evaluateOnCallFrame", callFrameId=scriptmgr.getFrameId(), expression='console.log(' + _getCmdParam() + ')' ) def _f_cmd(browser, tab, scriptmgr, params): scriptmgr.curr_frame = int(params[0]) def _n_cmd(browser, tab, scriptmgr, params): tab.call_method("Debugger.pause") def _s_cmd(browser, tab, scriptmgr, params): tab.call_method("Debugger.stepInto") def _c_cmd(browser, tab, scriptmgr, params): tab.call_method("Debugger.resume") def _sout_cmd(browser, tab, scriptmgr, params): tab.call_method("Debugger.stepOut") def _sover_cmd(browser, tab, scriptmgr, params): tab.call_method("Debugger.stepOver") def _debugon_cmd(browser, tab, scriptmgr, params): tab.debug = True print('debug on') def _debugoff_cmd(browser, tab, scriptmgr, params): tab.debug = False print('debug off') def _exit_cmd(browser, tab, scriptmgr, params): print('quit') exit(0) def _processCdbCmd(cmd_str, browser, tab, scriptmgr): global g_cmdstr g_cmdstr = cmd_str cmdlist = cmd_str.split(' ') if len(cmdlist) < 1: return cmd_hash = { 'b': _b_cmd, 'bc': _bc_cmd, 'bt': _bt_cmd, 'p': _p_cmd, 'f': _f_cmd, 'n': _n_cmd, 's': _s_cmd, 'sout': _sout_cmd, 'sover': _sover_cmd, 'c': _c_cmd, 'debugon': _debugon_cmd, 'debugoff': _debugoff_cmd, 'q': _exit_cmd, } if cmdlist[0] in cmd_hash: cmd_hash[cmdlist[0]](browser, tab, scriptmgr, cmdlist[1:]) else: print('not found %s cmd' % cmdlist[0]) def processCmd(browser, tab, scriptmgr, cmdline): try: if len(cmdline) > 0 : if cmdline[0] == '!': msg = eval(cmdline[1:]) else: _processCdbCmd(cmdline, browser, tab, scriptmgr) except Exception as e: print(e)