diff --git a/packages/wxt/src/core/utils/__tests__/content-scripts.test.ts b/packages/wxt/src/core/utils/__tests__/content-scripts.test.ts index 919ba4f75..34ae8e9f1 100644 --- a/packages/wxt/src/core/utils/__tests__/content-scripts.test.ts +++ b/packages/wxt/src/core/utils/__tests__/content-scripts.test.ts @@ -1,5 +1,8 @@ import { describe, expect, it, beforeEach } from 'vitest'; -import { hashContentScriptOptions } from '../content-scripts'; +import { + hashContentScriptOptions, + mapWxtOptionsToRegisteredContentScript, +} from '../content-scripts'; import { setFakeWxt } from '../testing/fake-objects'; describe('Content Script Utils', () => { @@ -30,4 +33,44 @@ describe('Content Script Utils', () => { expect(hash1).toBe(hash2); }); }); + + describe('mapWxtOptionsToRegisteredContentScript', () => { + it('preserves matchOriginAsFallback for dynamic registration', () => { + const contentScript = mapWxtOptionsToRegisteredContentScript( + { + matches: ['*://example.com/*'], + matchOriginAsFallback: true, + allFrames: true, + runAt: 'document_start', + world: 'MAIN', + }, + ['content-scripts/example.js'], + undefined, + ); + + expect(contentScript).toEqual({ + allFrames: true, + excludeMatches: undefined, + matchOriginAsFallback: true, + matches: ['*://example.com/*'], + runAt: 'document_start', + js: ['content-scripts/example.js'], + css: undefined, + world: 'MAIN', + }); + }); + + it('preserves false matchOriginAsFallback values', () => { + const contentScript = mapWxtOptionsToRegisteredContentScript( + { + matches: ['*://example.com/*'], + matchOriginAsFallback: false, + }, + ['content-scripts/example.js'], + [], + ); + + expect(contentScript.matchOriginAsFallback).toBe(false); + }); + }); }); diff --git a/packages/wxt/src/core/utils/content-scripts.ts b/packages/wxt/src/core/utils/content-scripts.ts index 16d7ee841..a4049321e 100644 --- a/packages/wxt/src/core/utils/content-scripts.ts +++ b/packages/wxt/src/core/utils/content-scripts.ts @@ -75,6 +75,7 @@ export function mapWxtOptionsToRegisteredContentScript( return { allFrames: options.allFrames, excludeMatches: options.excludeMatches, + matchOriginAsFallback: options.matchOriginAsFallback, matches: options.matches, runAt: options.runAt, js,