0

I have a very simple call to some server, using jQuery to make my life easier.

popup.js

    var url = "https://svcs.ebay.com/services/search/FindingService/v1";
      url += "?OPERATION-NAME=findItemsByKeywords";
      url += "&SERVICE-VERSION=1.0.0";
      url += "&SECURITY-APPNAME=LuisDavi-son19975-PRD-27f3a1ec0-de5a37b4";
      url += "&GLOBAL-ID=EBAY-US";
      url += "&RESPONSE-DATA-FORMAT=JSONP";
      url += "&REST-PAYLOAD";
      url += "&keywords=4%20Apple%20iPhone%20Model%20A1332%20FOR%20PARTS%20ONLY";

    var EbayPriceS = 0;
    var SeRiCount = 0;
    $(document).ready(function() {

        $.ajax({
            type: "POST",
             headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            dataType: 'jsonp',
            url: url,
            crossDomain : true,
            xhrFields: {
                withCredentials: true
            }
        })

        .done(function( root ) {

           SeRiCount = root.findItemsByKeywordsResponse[0].searchResult[0]["@count"];
                        alert(SeRiCount);
        })
        .fail( function(xhr, textStatus, errorThrown) {
            alert(xhr.responseText);
            alert(textStatus);
        });

 });

Basically, it boils down to returning me some data from eBay, and the thing is, that this works if I use this code in some local HTML file. (I have an alert that shows SeRiCount value)

However, if I try and run this same thing from a Chrome extension, I don't get the same thing. I get an error response. And my question would be, why?

manifest.json

{
  "manifest_version": 2,

  "name": "Bid Support Extension",
  "description": "This extension supports the adoption of bid resolution when buy the product.",
  "version": "1.0",

  "permissions": [
    "https://svcs.ebay.com/*"
  ],

  "browser_action": {
   "default_icon": "icon.png"

  },

  "content_scripts": [
    {
      "matches": ["https://www.shopgoodwill.com/*",  "https://www.ebay.com/sch/i.html?_from=*"],
      "js": ["jquery.min.js", "popup.js"]
    }
  ]
}

As you can see, nothing funky is going around in the manifest.json file either, and when I get the error log, it says this:

enter image description here

Am I missing something? Should I include some stuff in the manifest.json or I just can't make calls from Chrome extension to this server?

wOxxOm
  • 65,848
  • 11
  • 132
  • 136
Vlada
  • 145
  • 10
  • The error says jQuery is putting the code into a `script` DOM element, which makes it run in the web page context instead of the content script context ([more info](https://stackoverflow.com/a/9517879)). I don't know why jQuery does that so I think you should switch to `XMLHttpRequest` or `fetch`. – wOxxOm Nov 05 '18 at 05:57
  • @wOxxOm I really don't get why the current method does not work. It doesn't make any sense to me. – Vlada Nov 05 '18 at 06:20
  • 1
    I tried to explain that as best as I could. – wOxxOm Nov 05 '18 at 06:22

0 Answers0