Error: Promised response from onMessage listener went out of scope

I'm using fetching from OpenAI API. if response takes more than, let say 3 seconds. I get this error. I think something to do with timeout of connection. What should I do?
import type { PlasmoMessaging } from "@plasmohq/messaging";

const handler: PlasmoMessaging.MessageHandler = async (req, res) => {
try {
console.log("background: translate")
const body = { input_text: req.body.input_text};
const res2 = await fetch('http://localhost:3000/translate', {
method: 'POST',
headers: { 'Content-Type': 'application/json'},
body: JSON.stringify(body)
});
const {output_text} = await res2.json();
console.log(output_text);
res.send({...body, output_text: output_text});
} catch (err) {
console.log(err);
res.send({ error: err.message ?? "Unknown error" });
}
};

export default handler;
import type { PlasmoMessaging } from "@plasmohq/messaging";

const handler: PlasmoMessaging.MessageHandler = async (req, res) => {
try {
console.log("background: translate")
const body = { input_text: req.body.input_text};
const res2 = await fetch('http://localhost:3000/translate', {
method: 'POST',
headers: { 'Content-Type': 'application/json'},
body: JSON.stringify(body)
});
const {output_text} = await res2.json();
console.log(output_text);
res.send({...body, output_text: output_text});
} catch (err) {
console.log(err);
res.send({ error: err.message ?? "Unknown error" });
}
};

export default handler;
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?