Below Python Script I have used for my purpose. When I am in Firefox window it has failed to execute the javascript and thronging error. The error text also given below.
================The error message ====================
Traceback (most recent call last):
File "D:\pyth\copy active window process name.py", line 22, in
x=js2py.eval_js('var a = console.log(window.location.href); a');
File "D:\Python2020\lib\site-packages\js2py\evaljs.py", line 115, in eval_js
return e.eval(js)
File "D:\Python2020\lib\site-packages\js2py\evaljs.py", line 204, in eval
self.execute(code, use_compilation_plan=use_compilation_plan)
File "D:\Python2020\lib\site-packages\js2py\evaljs.py", line 199, in execute
exec (compiled, self._context)
File "", line 2, in
File "D:\Python2020\lib\site-packages\js2py\base.py", line 949, in call
return self.call(self.GlobalObject, args)
File "D:\Python2020\lib\site-packages\js2py\base.py", line 1464, in call
return Js(self.code(*args))
File "D:\Python2020\lib\site-packages\js2py\host\jseval.py", line 45, in Eval
executor(py_code)
File "D:\Python2020\lib\site-packages\js2py\host\jseval.py", line 51, in executor
exec (code, globals())
File "", line 2, in
File "D:\Python2020\lib\site-packages\js2py\base.py", line 321, in get
raise MakeError('TypeError',
js2py.internals.simplex.JsException: TypeError: Undefined and null dont have properties (tried getting property 'href')
Below Python Script I have used for my purpose. When I am in Firefox window it has failed to execute the javascript and thronging error. The error text also given below.
+++++++++++++++Python Script++++++++++++++++
import win32gui, win32process, psutil import js2py
def active_window_process_name(): try: pid = win32process.GetWindowThreadProcessId(win32gui.GetForegroundWindow()) return(psutil.Process(pid[-1]).name()) except: pass
windowTile = ""; while ( True ) : newWindowTile = win32gui.GetWindowText(win32gui.GetForegroundWindow()); if active_window_process_name() != 'firefox.exe': if( newWindowTile != windowTile ) : windowTile = newWindowTile ; print(active_window_process_name(),windowTile ); elif active_window_process_name() == 'firefox.exe': if(newWindowTile != windowTile ) : windowTile = newWindowTile ; window = win32gui.GetWindowText(win32gui.GetForegroundWindow()) ; x=js2py.eval_js('var a = console.log(window.location.href); a'); print(x)
================The error message ==================== Traceback (most recent call last): File "D:\pyth\copy active window process name.py", line 22, in
x=js2py.eval_js('var a = console.log(window.location.href); a');
File "D:\Python2020\lib\site-packages\js2py\evaljs.py", line 115, in eval_js
return e.eval(js)
File "D:\Python2020\lib\site-packages\js2py\evaljs.py", line 204, in eval
self.execute(code, use_compilation_plan=use_compilation_plan)
File "D:\Python2020\lib\site-packages\js2py\evaljs.py", line 199, in execute
exec (compiled, self._context)
File "", line 2, in
File "D:\Python2020\lib\site-packages\js2py\base.py", line 949, in call
return self.call(self.GlobalObject, args)
File "D:\Python2020\lib\site-packages\js2py\base.py", line 1464, in call
return Js(self.code(*args))
File "D:\Python2020\lib\site-packages\js2py\host\jseval.py", line 45, in Eval
executor(py_code)
File "D:\Python2020\lib\site-packages\js2py\host\jseval.py", line 51, in executor
exec (code, globals())
File "", line 2, in
File "D:\Python2020\lib\site-packages\js2py\base.py", line 321, in get
raise MakeError('TypeError',
js2py.internals.simplex.JsException: TypeError: Undefined and null dont have properties (tried getting property 'href')