{"record":{"id":"1372ab7f0f87c8e2","repo":"quasarframework/quasar","slug":"failed-to-send-message-to-packet-to","errorCode":null,"errorMessage":"Failed to send message to \"${packet.to}\".","messagePattern":"Failed to send message to \"(.+?)\"\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app-vite/exports/bex/private/bex-bridge.js","lineNumber":774,"sourceCode":"\n    if (!this.portList.includes(packet.to)) {\n      return Promise.reject(\n        `Tried to send message of type \"${packet.type}\" to \"${packet.to}\" but there is no such port registered`\n      )\n    }\n\n    if (port === void 0) {\n      return Promise.reject(\n        this.#type === 'background'\n          ? `Tried to send message of type \"${packet.type}\" to \"${packet.to}\" but the port is not available`\n          : `Tried to send message of type \"${packet.type}\" to \"${packet.to}\" but the port to background is not available to forward through`\n      )\n    }\n\n    try {\n      port.postMessage(packet)\n    } catch (err) {\n      this.warn(`Failed to send message to \"${packet.to}\".`, err)\n      return Promise.reject(err)\n    }\n\n    return Promise.resolve()\n  }\n\n  /**\n   * @param {{ id?: number, to: string, payload: any, messageType: \"event-send\" | \"event-response\", messageProps: any }} param\n   */\n  #sendMessage({\n    id = getRandomId(1_000_000),\n    to,\n    payload,\n    messageType,\n    messageProps\n  }) {\n    if (!Array.isArray(payload)) {\n      return this.#sendPacket({","sourceCodeStart":756,"sourceCodeEnd":792,"githubUrl":"https://github.com/quasarframework/quasar/blob/4841521b5f635a971eb9e2710e5542efd194691b/app-vite/exports/bex/private/bex-bridge.js#L756-L792","documentation":"#sendPacket is the bridge's core send routine: it calls port.postMessage(packet) on the underlying browser runtime port. If postMessage throws (e.g. the port has been disconnected because the other side closed, or the message isn't serializable), the promise rejects with the underlying error after logging this warning.","triggerScenarios":"Calling bridge.send()/#sendMessage while the receiving context (content script, popup, background) has disconnected; attempting to send a non-cloneable value (function, DOM node) in the packet; posting on a port whose counterpart page was reloaded by hot-reload.","commonSituations":"Extension service worker restarted in MV3 and stale ports were used; user closed the popup mid-request; dev rebuild reloaded the content script; sending state objects containing functions or class instances.","solutions":["Listen for port disconnect/onDisconnect and recreate the bridge before sending again","Serialize the payload — send only JSON-cloneable values (no functions, DOM nodes, class instances)","Wrap bridge.send() calls in try/catch (it returns a rejected promise) and retry after reconnection","Check the companion `err` for 'Attempting to use a disconnected port object' to confirm the cause"],"exampleFix":"// before\nbridge.send('save.data', { save: fn, el: document.body })\n// after\ntry {\n  await bridge.send('save.data', { data: JSON.parse(JSON.stringify(state)) })\n} catch (err) {\n  // recreate bridge/port then retry\n}","handlingStrategy":"try-catch","validationCode":"// ensure payload is structured-cloneable before sending\nfunction isCloneable(value) {\n  try { structuredClone(value); return true } catch { return false }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await bridge.send('my.event', payload)\n} catch (err) {\n  if (String(err).includes('disconnected port')) {\n    await reconnectBridge() // re-open port, then retry\n  } else if (!isCloneable(payload)) {\n    console.error('Payload not cloneable: strip functions/DOM nodes')\n  }\n}","preventionTips":["Send only JSON-safe data (no functions, DOM nodes, class instances)","Track port disconnect events and rebuild the bridge before subsequent sends","Resend pending messages after content-script/popup reload instead of using stale ports","Test message flows across service-worker restarts and page reloads"],"tags":["bex","port-disconnected","postmessage","serialization"],"backgroundTag":"disconnected-port-postmessage","analyzedSha":"4841521b5f635a971eb9e2710e5542efd194691b","analyzedAt":"2026-08-30T01:13:14.944Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}