0

I have looked all over but could not find an adequate solution for this. I have a Chrome Extension with JS and I need to be able to call a python script and pass in the current URL as a parameter. The JS gets the url of the current tab and has to somehow pass it into a python script which uses bs4 to scrape some data. I am very new to this so I am looking for a very minimal answer (sorry :( )

I need to send the "urlSend" in the below code to the python function and return the results back

chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => {
        let urlSend = tabs[0].url;
        //call python script somehow and pass in urlSend
    });

How can this be achieved

Sorry if I did something wrong in the question as I am new to this. Thanks for the help

  • Use [nativeMessaging](https://developer.chrome.com/extensions/nativeMessaging). – wOxxOm Apr 03 '21 at 02:24
  • is there an example to reference, I am having difficulty understanding how to implement. sorry if this is naive – Confused101 Apr 03 '21 at 03:32
  • It's linked inside that article. – wOxxOm Apr 03 '21 at 03:35
  • is there no other method to approach this? – Confused101 Apr 03 '21 at 04:19
  • Will something like this work?https://stackoverflow.com/questions/63658710/i-want-to-make-a-chrome-extension-that-will-take-url-from-browser-and-pass-it-to – Confused101 Apr 03 '21 at 04:30
  • No, it won't work. The only alternative is setting up a local http server in python which listens on a port so you can use `fetch` in the extension to communicate with that port. – wOxxOm Apr 03 '21 at 04:45
  • do you mind elaborating on that? I am having difficulty implementing native messaging – Confused101 Apr 03 '21 at 05:04
  • There should be zillions of examples on how to set up a server in python. As for making a network request in an extension, see [this example](https://stackoverflow.com/a/55292071). – wOxxOm Apr 03 '21 at 05:16
  • Do you mind explaining as to why it would not work as the use cases for both that link and my project are identical...pass url into python which returns scraped data. NativeMessaging does not seem to fit my level of expertise as I preferred a simpler option. If there are none, I will look into redesigning the project. Please let me know – Confused101 Apr 04 '21 at 00:38
  • I've added a comment in the topic you found. – wOxxOm Apr 04 '21 at 03:30

0 Answers0