MetaMask / MetaMask/metamask-extension

[Bug]: error messages in browser console when opening local file with file:// url

Open
#30,001 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

external-contributor regression-prod-12.6.2 Sev2-normal team-extension-platform type-bug
Dominant language
TypeScript
Stars
13.2k
Forks
5.6k
Avg merge
2d 5h
Merged PRs (30d)
451

Description

### Describe the bug

When opening a html document via file:// url, i.e. a local file, the following two error messages appear in the console every time.

![Image](https://github.com/user-attachments/assets/922a9354-5394-437d-9e59-22be5d2b779a)

Extension ed7763e0-afa2-4da4-bee8-4d7f58fd6704 is metamask, verified by opening `moz-extension://ed7763e0-afa2-4da4-bee8-4d7f58fd6704/home.html`.

(empty.html is just ``)

Opening the same file via temporary local server does not cause these errors.

### Expected behavior

No errors polluting the log.

### Screenshots/Recordings

_No response_

### Steps to reproduce

Make a html file, open it directly without a local server, i.e. via file:// url, observe browser console.

### Error messages or log output

```shell
SyntaxError: An invalid or illegal string was specified contentscript.js:1
_postMessage moz-extension://ed7763e0-afa2-4da4-bee8-4d7f58fd6704/scripts/contentscript.js:1
_write moz-extension://ed7763e0-afa2-4da4-bee8-4d7f58fd6704/scripts/contentscript.js:1
_handshake moz-extension://ed7763e0-afa2-4da4-bee8-4d7f58fd6704/scripts/contentscript.js:1
d moz-extension://ed7763e0-afa2-4da4-bee8-4d7f58fd6704/scripts/contentscript.js:1
initStreams moz-extension://ed7763e0-afa2-4da4-bee8-4d7f58fd6704/scripts/contentscript.js:1
initStreams moz-extension://ed7763e0-afa2-4da4-bee8-4d7f58fd6704/scripts/contentscript.js:1
[3]< moz-extension://ed7763e0-afa2-4da4-bee8-4d7f58fd6704/scripts/contentscript.js:1
i moz-extension://ed7763e0-afa2-4da4-bee8-4d7f58fd6704/scripts/contentscript.js:1
e moz-extension://ed7763e0-afa2-4da4-bee8-4d7f58fd6704/scripts/contentscript.js:1
moz-extension://ed7763e0-afa2-4da4-bee8-4d7f58fd6704/scripts/contentscript.js:1
#injectIntoIsolatedWorld resource://gre/modules/ExtensionContent.sys.mjs:687
inject resource://gre/modules/ExtensionContent.sys.mjs:672
AsyncFunctionNext self-hosted:800
DOMException: An invalid or illegal string was specified
_postMessage file:///D:/Desktop/empty.html:1
_write file:///D:/Desktop/empty.html:1
_handshake file:///D:/Desktop/empty.html:1
f file:///D:/Desktop/empty.html:1
[1] file:///D:/Desktop/empty.html:1
```

### Detection stage

In production (default)

### Version

12.6.2

### Build type

None

### Browser

Firefox

### Operating system

Windows

### Hardware wallet

_No response_

### Additional context

_No response_

### Severity

_No response_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue by opening an empty HTML file through a file:// URL in Firefox and compare it with the same file served locally. Start from the contentscript.js _postMessage/_handshake stack frames and the file:///D:/Desktop/empty.html frames, then trace the extension messaging path. Done means opening local files no longer produces these console errors while served files continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.