0

I'm new in chrome extension, I'm trying to develop a chrome extension that communicates with my python web API. It throws an error.

These are permissions in manifest.json:

 "background": {
     "scripts": ["jquery-3.2.1.min.js","backgroundScript.js"],
     "persistent": true
 },
 "permissions": [
     "tabs",
     "http://*/",
     "https://*/",
     "webNavigation",
     "*://*/*",
     "http://127.0.0.1:5000/*" 
 ]

This is ajax request in backgroundScript.js:

let obj = {
    "url": response
};

$.ajax({
    type: "POST",
    url: "http://127.0.0.1:5000/api/scrape_company", // URL de l'API
    xhrFields: {
        withCredentials: true
    },
    data: obj, 
    unique: true,
    dataType:'json',
    success: function (result) {
        if (result=== obj["url"] + ': scrapped and inserted with success') {
            alert(result);
        } else{
            alert('Check your url !');
        }
    },
    error: function () {
        alert('Please wait until the scraping is done');
    }
});

And this is my popup.html :

    ...
    <script type="text/javascript" src="jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="backgroundScript.js"></script>
    
    <link href="http://127.0.0.1:5000/api/scrape_company">
 
    
  </head>

  

How can I communicate with my web server? thanks in advance

Aziza Kasenova
  • 1,501
  • 2
  • 10
  • 22
  • The background script runs in a hidden background page and should be loaded only via manifest.json, not in popup.js. After you fix it make sure to click the reload icon for your extension on `chrome://extensions` page. See also [how to see background.js console?](/a/10258029). Note that the popup is a separate window so it has its own separate devtools: right-click inside the popup and select "inspect" in the menu. – wOxxOm Mar 28 '21 at 13:47
  • Are you sure that the ports match and the port is open? – Rojo Mar 28 '21 at 13:50
  • @wOxxOm thanks for your reply, I omitted the background script from popup but unfortunately it's the same error : connection refused – Abir Khaldi Mar 28 '21 at 13:54
  • @Rojo sorry I'm new to all of that, how can I check if the port is open or not . and I have to note that I test it with postman before using the chrome extension and it worked fine – Abir Khaldi Mar 28 '21 at 13:57
  • Could you try running your extension with Firefox? I feel that Firefox is better at debugging and having more descriptive errors. If you need help, you can let me know and I will start a private room. – Rojo Mar 28 '21 at 13:59
  • Thank you @Rojo, the problem is that I have to work with chrome. Could you please help me in that ? – Abir Khaldi Mar 28 '21 at 14:07

0 Answers0