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!
No description
No description
No description
No description
12 Replies
yummyfresh
yummyfresh•2mo ago
I also tried adding our extension ID and running the script in Main World and it doesn't work
Arcane
Arcane•2mo ago
@yummyfresh has reached level 1. GG!
Mesh
Mesh•2mo ago
@lab I am also having the same issue. Is there something I am missing in the messaging docs?
lab
lab•2mo ago
Hm is the cs in the main world? The code looks about right to me
Mesh
Mesh•2mo ago
yup I have set up the CSConfig to be in main world.
Arcane
Arcane•2mo ago
@Mesh has reached level 1. GG!
Mesh
Mesh•2mo ago
any guidance here, spent the last few days debugging this as well :/
yummyfresh
yummyfresh•2mo ago
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?
filthytone
filthytone•2mo ago
You can’t send response because it’s not json serializable .. send the awaited response.json() instead
yummyfresh
yummyfresh•2mo ago
thank you @filthytone -- this worked
YAGPDB.xyz
YAGPDB.xyz•2mo ago
Gave +1 Rep to @filthytone (current: #5 - 20)
lab
lab•2mo ago
Oooh I didn't notice that lol xD
Want results from more Discord servers?
Add your server