SOLVED: Porting from chrome...can't send $.post?

Hey there! I have a chrome extension for a Reddit mod-team where I create a few buttons on the page that send out a POST request to the Reddit API, ultimately simplifying some of our work. I have always done so like $.post(‘URL’, { data }).done(function() { //do something });. POSTing this way has always worked on the chrome extension AND the previous versions of our firefox addon using the Add-on SDK. However I’m trying to port our exact chrome extension over, using the new WebExtensions and this just will not work with WebExtensions for whatever reason.

I had to change the way I handled storage (from chrome.storage.sync to browser.storage.local). After that, everything works perfectly when testing except well…it doesn’t send the request at all. I know there is a new requests module with WebExtensions and I have tried it as well but didn’t have much luck and to be honest would really just like to get this to work the way it always has. Nothing comes up in the firefox console at all, nor can i see any request go through from the network tab. The only way I’ve actually gotten this to work correctly with this new firefox WebExtension port was by manually sending the code through FF console… Any help would be very much appreciated!!

EDIT: SOLVED!
Turns out that when porting over to the new WebExtension, it really doesn’t like it if you use a relative URL in the request (at least in this case haha). I feel pretty dumb for not thinking about it, and probably should’ve been supplying a base domain string in each requests URL before adding an endpoint to begin with, but it didn’t really cross my mind since it had never been an issue with any previous Chrome version of the extension, or Firefox version using the older add-on SDK.

I don’t think there is.

Native XHRs should work just fine, which leaves two options:

  • $.post does something stupid
  • its a bug like this

Where (background/content) are you doing your request, by the way?

You also might need to add the URL to the permissions like this:

https://github.com/Noitidart/Fake-Location/blob/d589f734996c5b405cce8f6c021dbd627ea47076/src/webextension/manifest.json#L26

Thanks for the reply! My apologies, perhaps it isn’t new. What I really mean is that until trying to port the chrome version over using the new WebExtensions, I’d never had an issue sending the request this way with the Addon SDK so I never needed to look into it any further. I’m not sure it would be the same as that bug. I’m sending it from the main content script as I always have. Basically it works like this - I have 2 buttons being created. Both are actually just drop-down lists with several buttons in each. I hook the functions that create those by calling them on document.ready, and when each button in the drop-down list is created, i’m adding a click listener to each one of them that calls the function where I send the request. When trying to use the WebExtension request module with XHRs I also included the webRequest permission. The farthest I got trying it that way was seeing a Mixed-Content/Cross-Origin Request Blocked error, but when manually sending it through the FF console, it worked… I created this gist with only one of the buttons included to keep it as short as possible in case this may help. https://gist.github.com/ericwoolard/0bc20d5a5b7fb6385c25cd24bc527c07

Unfortunately, I can say that I’ve made sure every relevant URL was included in my permissions block of the manifest, so i wouldnt imagine it would be a permissions issue

Try this:

Spy plugin Chrome

Spy allows to send POST/PUT/GET/PATCH request from Chrome