Skip to content

Workaround firefox warning and inject if it is html or unknown#89

Merged
mrts merged 1 commit intomainfrom
warn
Apr 10, 2026
Merged

Workaround firefox warning and inject if it is html or unknown#89
mrts merged 1 commit intomainfrom
warn

Conversation

@metsma
Copy link
Copy Markdown
Contributor

@metsma metsma commented Nov 20, 2025

TypeError: can't access property "name", s.dataset is undefined

WE2-1143

Signed-off-by: Raul Metsma raul@metsma.ee

@miamibc
Copy link
Copy Markdown

miamibc commented Nov 20, 2025

Hello. Thank you, little bit better but still extension throws error.

GET https://krediidiraportid.ee/sitemap.xml [HTTP/1.1 200 OK 304ms]

XML Parsing Error: not well-formed
Location: 
Line Number 7, Column 33:
SyntaxError: An invalid or illegal string was specified [content.js:207:37](moz-extension://341d79c1-7e85-4808-b051-6a4ea0e25c20/content.js)
    injectPageScript moz-extension://341d79c1-7e85-4808-b051-6a4ea0e25c20/content.js:207
    <anonymous> moz-extension://341d79c1-7e85-4808-b051-6a4ea0e25c20/content.js:306
    <anonymous> moz-extension://341d79c1-7e85-4808-b051-6a4ea0e25c20/content.js:309
    #injectIntoIsolatedWorld resource://gre/modules/ExtensionContent.sys.mjs:683
    inject resource://gre/modules/ExtensionContent.sys.mjs:668
    injectInto resource://gre/modules/ExtensionContent.sys.mjs:518
    AsyncFunctionNext self-hosted:800
image

Solution can be - don't activate plugin on pages with mime type other than HTML.
Or, few more IFs and tests. Testpage for XML can be any sitemap: https://krediidiraportid.ee/sitemap.xml

@metsma metsma changed the title Workaround firefox warning Workaround firefox warning and inject if it is html or unknown Nov 20, 2025
@miamibc
Copy link
Copy Markdown

miamibc commented Nov 20, 2025

XML Parsing Error: not well-formed
Location: 
Line Number 7, Column 33:
SyntaxError: An invalid or illegal string was specified [content.js:214:37](moz-extension://239bb713-a580-45e0-966f-9c74664c44fc/content.js)
    injectPageScript moz-extension://239bb713-a580-45e0-966f-9c74664c44fc/content.js:214
    <anonymous> moz-extension://239bb713-a580-45e0-966f-9c74664c44fc/content.js:313
    <anonymous> moz-extension://239bb713-a580-45e0-966f-9c74664c44fc/content.js:316
    #injectIntoIsolatedWorld resource://gre/modules/ExtensionContent.sys.mjs:683
    inject resource://gre/modules/ExtensionContent.sys.mjs:668
    injectInto resource://gre/modules/ExtensionContent.sys.mjs:518
    AsyncFunctionNext self-hosted:800

I think your document type detection is not effective enough. I removed all your checks and added this one:

if (!document instanceof HTMLDocument) return;

Tested with

image

Detection works, but i don't understand what's going on after detection.

@miamibc
Copy link
Copy Markdown

miamibc commented Nov 20, 2025

Found reason.

instanceof gives true on XML docs, because XMLDocument and HTMLDocument both extends same type.

Changed verification to

		if (typeof( document ) !== 'HTMLDocument') {
			return;
		}

This is final version of injectPageScript function


    function injectPageScript() {
        if (typeof( document ) !== 'HTMLDocument') return;
        if (!document.querySelector("script[data-name='TokenSigning']")) {

            const s = document.createElement("script");
            s.type = "text/javascript";
            if (s.dataset) {
                s.dataset.name = "TokenSigning";
                s.dataset.by = "Web-eID extension";
            }
            else {
                s.setAttribute("data-name", "TokenSigning");
                s.setAttribute("data-by", "Web-eID extension");
            }
            if (browser.runtime.getManifest()["manifest_version"] >= 3) {
                s.src = browser.runtime.getURL("token-signing-page-script.js");
            }
            else {
                s.innerHTML = "(" + pageScript + ")();";
            }
            (document.head || document.documentElement).appendChild(s);
        }
    }

@metsma
Copy link
Copy Markdown
Contributor Author

metsma commented Nov 20, 2025

Maybe if (document.contentType !== "text/html") {

@miamibc
Copy link
Copy Markdown

miamibc commented Nov 20, 2025

I think

 if (typeof( document ) !== 'HTMLDocument') return;

is enough. Result will be the same, from information i know.

@metsma
Copy link
Copy Markdown
Contributor Author

metsma commented Nov 20, 2025

I think

 if (typeof( document ) !== 'HTMLDocument') return;

is enough. Result will be the same, from information i know.

This gives me 'object'

@miamibc
Copy link
Copy Markdown

miamibc commented Nov 20, 2025

Uh...
Here i found nice way to detect class name: https://stackoverflow.com/questions/1249531/how-to-get-a-javascript-objects-class

document.constructor.name => "HTMLDocument"

Let's change line 1 to

if (document.constructor.name !== 'HTMLDocument') return;

@miamibc
Copy link
Copy Markdown

miamibc commented Nov 21, 2025

Checked last artifact download URL: https://github.com/web-eid/web-eid-webextension/actions/runs/19536024038/artifacts/4626976308

Everything works correct on XML, HTML and text pages, no errors.

Comment thread src/content/TokenSigning/injectPageScript.ts Outdated
TypeError: can't access property "name", s.dataset is undefined

WE2-1143

Signed-off-by: Raul Metsma <raul@metsma.ee>
@miamibc
Copy link
Copy Markdown

miamibc commented Jan 16, 2026

Sorry, maybe it's time to merge? Or what we are waiting for? This is what i currently have installed from plugin repo:

Author Riigi Infosüsteemi Amet
Version 2.2.1
Last Updated 17 April 2025

@mrts
Copy link
Copy Markdown
Member

mrts commented Jan 16, 2026

We are waiting for testers' testing. We have a deliberate process and release cadence, the new version with this fix will be published to browser store during the next release cycle in end of Q1 or so.

@mrts mrts merged commit 10e87e3 into main Apr 10, 2026
2 checks passed
@mrts mrts deleted the warn branch April 10, 2026 12:44
@mrts
Copy link
Copy Markdown
Member

mrts commented Apr 10, 2026

@miamibc Thanks a lot for bringing this up! It is now tested and will be released to browser extension stores during April or early May.

@miamibc
Copy link
Copy Markdown

miamibc commented Apr 10, 2026

Very funny. I hope youll be replaced by ai soon, guys. Half of year to change 3 lines of code, seriously?)

@mrts
Copy link
Copy Markdown
Member

mrts commented Apr 10, 2026

I understand your frustration. As mentioned earlier, we have a deliberate planning, testing and delivery process and release cadence, this causes the delay in case of non-critical issues like this. We intend to keep using the deliberate, thorough process in the future as well considering the impact of the project, I hope you understand the value of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants