Skip to content

fixIframeContentWindow setter throws "Cannot assign to read only property 'srcdoc'" #546

@Mkopl360

Description

@Mkopl360

File: packages/fingerprint-injector/src/utils.js, inside fixIframeContentWindow() → handleIframeCreation() → the srcdoc setter

The problem — two consecutive lines contradict each other:

set(newValue) {
    addContentWindowProxy(this);
    // Step 1: Lock the property as NON-WRITABLE
    Object.defineProperty(iframe, 'srcdoc', {
        configurable: false,
        writable: false,      // ← srcdoc is now read-only
        value: _srcdoc,
    });
    // Step 2: Try to assign to it — THROWS because step 1 just made it read-only
    _iframe.srcdoc = newValue;  // ← "Cannot assign to read only property 'srcdoc'"
}

Step 1 locks the property as writable: false. Step 2 immediately tries to assign a new value to that same property. In strict mode (which TypeScript-compiled code uses), this throws an error. The srcdoc content never gets set, and the iframe never loads.

The fix — use setAttribute instead of property assignment:

// Before
_iframe.srcdoc = newValue;
// After
_iframe.setAttribute('srcdoc', newValue);

setAttribute writes directly to the DOM attribute level, completely bypassing the JavaScript property descriptor. It doesn't care whether the JS property is writable or not — the browser still processes it and loads the iframe content correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working.t-toolingIssues with this label are in the ownership of the tooling team.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions