Skip to content

Commit 2233bea

Browse files
committed
Workaround firefox warning and inject if it is html or unknown
TypeError: can't access property "name", s.dataset is undefined WE2-1143 Signed-off-by: Raul Metsma <[email protected]>
1 parent 678cd45 commit 2233bea

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
npm run test clean build package
3636
3737
- name: Upload artifacts
38-
uses: actions/upload-artifact@v4
38+
uses: actions/upload-artifact@v5
3939
with:
4040
name: web-eid-webextension-${{github.run_number}}
4141
path: dist/

.github/workflows/codeql.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ jobs:
2222
uses: actions/checkout@v5
2323

2424
- name: Initialize CodeQL
25-
uses: github/codeql-action/init@v3
25+
uses: github/codeql-action/init@v4
2626
with:
2727
languages: javascript
2828
queries: +security-and-quality
2929

3030
- name: Autobuild
31-
uses: github/codeql-action/autobuild@v3
31+
uses: github/codeql-action/autobuild@v4
3232

3333
- name: Perform CodeQL Analysis
34-
uses: github/codeql-action/analyze@v3
34+
uses: github/codeql-action/analyze@v4

src/content/TokenSigning/injectPageScript.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,25 @@ export default function injectPageScript(): void {
3535
* https://github.com/open-eid/chrome-token-signing/blob/master/extension/page.js
3636
*/
3737
if (!document.querySelector("script[data-name='TokenSigning']")) {
38+
// Inject if the document is HTML, or if the doctype is missing/unknown.
39+
const doctypeName = document.doctype ? String(document.doctype.name).trim().toLowerCase() : "";
40+
const docElName = document.documentElement ? String(document.documentElement.nodeName).trim().toLowerCase() : "";
41+
const isHtml = doctypeName === "html" || docElName === "html";
42+
const isUnknownDoctype = !document.doctype || doctypeName === "";
43+
if (!isHtml && !isUnknownDoctype) {
44+
// Do not inject the script if the document is explicitly non-HTML (e.g. XML)
45+
return;
46+
}
3847
const s = document.createElement("script");
3948

4049
s.type = "text/javascript";
41-
s.dataset.name = "TokenSigning";
42-
s.dataset.by = "Web-eID extension";
50+
if (s.dataset) {
51+
s.dataset.name = "TokenSigning";
52+
s.dataset.by = "Web-eID extension";
53+
} else {
54+
s.setAttribute("data-name", "TokenSigning");
55+
s.setAttribute("data-by", "Web-eID extension");
56+
}
4357

4458
if (browser.runtime.getManifest()["manifest_version"] >= 3) {
4559
s.src = browser.runtime.getURL("token-signing-page-script.js");

0 commit comments

Comments
 (0)