Not able to print an API response in content script despite getting the response in network logs
Have a content script that, when a button is clicked, uses Plasmo's messaging framework to make an API request via a background script
Everything works fine: the relevant data is sent, received by the API, and a good response is sent back from the API ('healthy'), but for some reason the background script is not passing the response back to our content script. When we log the response, it's an empty object.
Images:
1. is the call to our background script from our content script
2. is the background script
3. is the empty object in our console logs
4. is the confirmed healthy response from our network logs
Have tried a bunch of debugging to no avail. Thanks!
12 Replies
I also tried adding our extension ID and running the script in Main World and it doesn't work
@yummyfresh has reached level 1. GG!
@lab I am also having the same issue. Is there something I am missing in the messaging docs?
Hm is the cs in the main world?
The code looks about right to me
yup I have set up the CSConfig to be in main world.
@Mesh has reached level 1. GG!
any guidance here, spent the last few days debugging this as well :/
hey @lab — does the content script need to be in main world for it to receive the api response from background?
If yes, even when we test it as such it still shows the weird empty object that I put in the screenshots. any other possible issues / fixes?
You can’t send response because it’s not json serializable .. send the awaited response.json() instead
thank you @filthytone -- this worked
Gave +1 Rep to @filthytone (current:
#5
- 20
)Oooh I didn't notice that lol xD