# Cannot access before initialization, at the top level

> Our popup opened a panel before that panel's const existed. The ReferenceError stopped the rest of the script, so full screen was blank from every tab.

Source: https://mosaicbrowser.com/blog/top-level-call-killed-the-popup

## A top-level call that killed every panel of our popup

Our popup opened a panel before that panel's const existed. The ReferenceError stopped the rest of the script, so full screen was blank from every tab.

![The file parsed, and nothing below one line ran](https://mosaicbrowser.com/covers/top-level-call-killed-the-popup.webp)

`Cannot access 'authRows' before initialization` is what our companion popup threw on 29 September 2026, and it threw it at the top level of the script. A `ReferenceError` there does not break one feature. It stops the script at the line that threw, so nothing written below that line ever runs. In our case that meant no tools panel, no notes wiring and a blank page every time anyone opened the popup in full screen, from any tab. Every check we had that parsed the file stayed green, because the file was fine as text.

## What "cannot access before initialization" means at the top level

`let`, `const` and `class` bindings exist from the start of their scope, but they cannot be read until the line that declares them has run. The stretch in between is the temporal dead zone. Reading a binding inside it throws, where an old `var` would have handed back `undefined` and carried on.

Function declarations are different: they are hoisted whole, so you can call one from the top of a file. That is exactly what makes this bug easy to write. The call works. The function starts running. Then it reaches for a `const` that sits a few hundred lines further down and has not been evaluated yet, and the throw comes from inside a function that was perfectly legal to call.

## How it happened in our popup

The companion is the extension that runs inside every Mosaic profile, with the profile's notes, saved logins and, since that day, an Auth panel of two-factor codes. Its popup reads a `tab=` query to decide which panel to open first. That decision sat near the top of `popup.js`:

```
const QUERY = new URLSearchParams(location.search)
// ...
if (QUERY.get('tab')) showPanel(QUERY.get('tab'))

```

`showPanel` reaches into the panel it opens. The new Auth panel's code timer lives beside `const authRows`, several hundred lines below. So the call ran, `showPanel` touched `authRows`, and the engine threw before the rest of the file had been evaluated.

The part that made it total is the full-screen button. It opens `popup.html?full=1&tab=<panel>`, so in full screen the `tab=` query is always present and the branch is always taken. Full screen was not broken on the Auth tab. It was broken on every tab, because whichever panel you came from, the startup code ran before the bindings existed.

The small popup, opened from the toolbar, has no query and never took the branch. That is how a page could be dead in one window and fine in the other.

Mosaic is a desktop app

Email yourself the link and open it on your computer.

[How it works: Fingerprints set inside the browser](https://mosaicbrowser.com/features/engine)

## Why nothing reported it

There was no red mark anywhere we looked. A popup's console belongs to the popup, and nobody opens DevTools on an extension popup to see why it is empty. The build had a check that the companion's files parse in every configuration, and they did. A parse answers "is this JavaScript", and this was JavaScript. Whether it throws depends on what runs first, and that only shows when something runs it.

We found it by driving the popup over the Chrome DevTools Protocol and reading what it actually did, which is how every fault in that panel was found. The same rule shows up in [the geolocation spoof that answered once](https://mosaicbrowser.com/blog/geolocation-answered-once): the test that matters is running the thing the way a person does, not reading it.

## The fix, and the check that holds it

The panel choice now runs last, after every top-level declaration it could close over. Running it from `DOMContentLoaded` would also have worked, because a classic script finishes evaluating before that event fires. We moved the call, and a comment above it now says it is the last line of the script on purpose.

The check was harder to write than the fix. `check:companion` now finds the line that reads `QUERY.get('tab')` and lists every `const` declared at column 0 below it. A `const` at column 0 is module scope; anything indented is inside a function and will exist by the time a handler runs. Any name on that list fails the build:

```
popup.js chooses a panel before 6 top-level bindings exist (...)
— that throws and kills the rest of the script

```

We put the fault back to see it fire, and it named six bindings. A check that has never failed is not evidence of anything, so that run is part of the check.

## The same error, once more, in a test runner

This was not the first time a dead-zone read cost us. Our detection suite once ran, drove six detectors, wrote its report, cleaned up its profile and exited 0. Every row in the report said `error Cannot access 'environment' before initialization`. A `let environment` had been declared under the report heading, two hundred lines below the loop that passed it on. It threw for every test in every run.

A run where every row is our own exception describes our script, not the browser it was pointed at. The runner now groups errors by message, says so in plain words when every row failed, and exits with a non-zero code. [A retired detector that answers 200](https://mosaicbrowser.com/blog/dead-detector-returns-200) is the same trap from the other side: a run that finished is not a run that measured anything. And [running 49 fingerprint tests unattended](https://mosaicbrowser.com/blog/automating-fingerprint-tests) has the rest of what that runner had to learn.

## If you hit this error

1. Read the name in the message. It is the binding, not the function that touched it.
2. Find the first top-level statement that calls into code using that binding. That call is the problem, not the declaration.
3. Move the call below the last declaration it can reach, or start it from `DOMContentLoaded`.
4. Look for every way the call gets reached. Ours depended on a query string only one button sent.
5. Run the page, not a parser. A syntax check cannot see an error that depends on order.

The companion is one of the pieces described in [introducing Mosaic](https://mosaicbrowser.com/blog/introducing-mosaic), and since September its full-screen view opens on whichever tab you left.

## Sources

1. [MDN: ReferenceError: can't access lexical declaration 'X' before initialization](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cant_access_lexical_declaration_before_init), read November 3, 2026

## Questions

### What does "Cannot access 'x' before initialization" mean?

Code read a let, const or class binding after its scope began but before the line that declares it had run. That window is the temporal dead zone, and reading a binding inside it throws a ReferenceError instead of returning undefined.

### Why does one ReferenceError at the top level break the whole page?

An uncaught exception while a classic script is being evaluated stops that script at the throw. Everything below it is never run: no later functions are wired up, no listeners are added, and the page looks blank or dead even though the file parsed.

### How do I fix a temporal dead zone error at the top level?

Move the startup call below every declaration it can reach, usually to the very end of the file, or run it from an event that fires after the script has finished, such as DOMContentLoaded. Hoisting the function does not help, because it is the variable the function reads that is not ready.

### Can a syntax check or a type checker catch this?

Not reliably. The file is valid JavaScript, so a parse passes. A checker can flag a binding used directly before its declaration, but when the use is inside a function called early, whether it throws depends on the order things run in, not on the text.

## Related

[A spoof that answers once: the geolocation bug we shipped](https://mosaicbrowser.com/blog/geolocation-answered-once): A geolocation spoofing timeout we shipped: the first getCurrentPosition got the IP's coordinates, every later call failed with code 3. One latch was to blame.

[A retired bot test can still answer 200 and look like a pass](https://mosaicbrowser.com/blog/dead-detector-returns-200): Antoine Vastel's fp-scanner demo now serves his homepage with HTTP 200, which a challenge reader scores as a pass. His tests moved; here is where.

[Running 49 fingerprint tests unattended, and what that takes](https://mosaicbrowser.com/blog/automating-fingerprint-tests): To automate browser fingerprint testing, tell a failed profile from a dead site, an unreadable page and your own bug. Our runner names each across 49 rows.

[Introducing Mosaic, an anti-detect browser that lives on your machine](https://mosaicbrowser.com/blog/introducing-mosaic): Mosaic runs its own Chromium, draws each profile from a real machine and matches it to the proxy IP. Profiles stay on disk. One plan, no per-profile fees.

[One pasted --disable-features deleted all of ours](https://mosaicbrowser.com/blog/disable-features-merge): Chromium reads only the last --disable-features on its command line. One extra flag silently re-enabled everything we turn off, so now we merge them.

[Headless is not a way to hide, it is a way to be seen](https://mosaicbrowser.com/blog/headless-is-a-signal): Headless Chrome names itself HeadlessChrome in its user agent and drops the real GPU. Why our background work runs headed, off-screen, instead.





[Is Camoufox still maintained? Reading the repository](https://mosaicbrowser.com/blog/is-camoufox-maintained): Is Camoufox still maintained? Its repository answers better than forums do: compare the latest release's date and Firefox base with today's Firefox.

## Mosaic, on your own computer

The browser this blog is about: its own Chromium, fingerprints from real machines and a proxy IP per profile. Free covers 3 profiles with no card, and Pro is $25 a month for any number of them.

Mosaic is a desktop app

Email yourself the link and open it on your computer.
