Solved.
Evidently
chrome.runtime.sendNativeMessage(id, {}, async _ => {
fetch()
});
runs before the bash script that is used for Native Messaging host completes at
php -S localhost:8000 -t /path/to/host/ & sendMessage # note use of &
where sendMessage send a simple message to background.js.
The solution is to await 15 milliseconds before calling fetch()
await new Promise(resolve => setTimeout(resolve, 15));
try {
const response = await fetch(
{
// cache: 'no-store',
mode: 'cors',
method: 'get',
signal,
}
);
9 and occasionally 10 milliseconds still throws network error.
Or, make HEAD request until Response.ok from server
for await (const request of (async function* stream() {
while (true) {
try {
} catch(e) {
console.warn(e.message);
yield;
}
}
})());
then make the GET request.
On Sunday, August 23, 2020 at 7:07:03 AM UTC-7 wOxxOm wrote: