Skip to content

Commit cf9ad96

Browse files
committed
Use iframe's actual origin for postMessage instead of hardcoded value
Previously hardcoded 'https://listen.libbyapp.com' as target origin, but Libby uses dynamic subdomains (e.g., dewey-abc123.listen.libbyapp.com). This caused postMessage to fail with origin mismatch error. - Extract actual origin from iframe.src URL - Fall back to base domain if URL parsing fails - Add console logging for debugging - Fixes: "The target origin provided does not match the recipient window's origin"
1 parent ed39da6 commit cf9ad96

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

chrome-extension/content/content.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,21 @@
324324

325325
this.uiManager.updateState('extracting');
326326

327+
// Get the actual origin from the iframe's URL (supports subdomains)
328+
let targetOrigin = 'https://listen.libbyapp.com'; // fallback
329+
try {
330+
const iframeUrl = new URL(iframe.src);
331+
targetOrigin = iframeUrl.origin;
332+
console.log('[Libby Downloader] Target origin:', targetOrigin);
333+
} catch (error) {
334+
console.warn('[Libby Downloader] Failed to parse iframe URL, using fallback origin');
335+
}
336+
327337
iframe.contentWindow.postMessage(
328338
{
329339
type: MessageTypes.EXTRACT_LIBBY_BOOK,
330340
},
331-
'https://listen.libbyapp.com'
341+
targetOrigin
332342
);
333343

334344
this.extractionTimeout = setTimeout(() => {

0 commit comments

Comments
 (0)