serversideup/webext-bridge

Add timeout for sendMessage

noamloewenstern opened this issue · 1 comments

I would find it useful to add an option for timeout waiting for response, when calling "sendMessage".
Something like this:

const resp = await sendMessage('messageID', { msgData: 'data' }, `content-script@123`, { timeout: 3000 })

That's a good idea. While I don't have the resources at this time to implement it in the library, this should work as quick-workaround:

 This code snippet has not been tested

import pTimeout from 'p-timeout'

try {
  const resp = await pTimeout(
    sendMessage('messageID', { msgData: 'data' }, `content-script@123`),
    { milliseconds: 3000 }
  )
} catch (err) {
  // [TimeoutError: Promise timed out after 3000 milliseconds]
}