Fix: Prevent authorization request from incorrect origin due to chrome pre-rendering fixes #1293 (#1308)

* fix: prevent authorization requests from incorrect url when pages are pre-rendered

* lint
This commit is contained in:
Francis O'Brien 2024-03-18 15:29:20 +00:00 committed by GitHub
parent 647747ac30
commit d00119dc5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -22,13 +22,13 @@ export default function handler<TMessageType extends MessageTypes> ({ id, messag
const isExtension = !port || port?.name === extensionPortName;
const sender = port?.sender;
if (!sender) {
if (!isExtension && !sender) {
throw new Error('Unable to extract message sender');
}
const from = isExtension
? 'extension'
: (sender.tab?.url) || sender.url || '<unknown>';
: sender?.url || sender?.tab?.url || '<unknown>';
const source = `${from}: ${id}: ${message}`;
console.log(` [in] ${source}`); // :: ${JSON.stringify(request)}`);