Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
executing javascript code thought chrome dev tools protocol

I'm trying to execute some javascript code through CDTP and PyChromeDevTools library. The following code works:

from terminal:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222

import PyChromeDevTools
chrome.Network.enable()
chrome.Page.enable()

script="t='hi,';c='this code works on the same line';console.log(t,c)"
chrome.Runtime.evaluate(expression=script)

I have some trouble when I need to inject complex js code not on the same line, for example function with javascript requests ecc..

script="t='hi,';
c='this code works not on the same line don't work ';
console.log(t,c)"
chrome.Runtime.evaluate(expression=script)

is it possible equal javascript file to runtime evaluate ? like this:

chrome.Runtime.evaluate(expression=file.js)

documentation of CDTP

https://chromedevtools.github.io/devtools-protocol/

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should just load a js code from a file into str variable

def load_text(filename, mode='r', encoding='utf-8'):
    with open(filename, mode, encoding=encoding) as f:
        txt = f.read()
return txt

file_js = load_text('file.js')
chrome.Runtime.evaluate(expression=file_js)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!