Build Passed, Browser Still White: When Missing APIs Like findLast and randomUUID Blank the Screen
Build passed, why do some browsers still white-screen?
Build passing means the toolchain produced an artifact according to the current configuration. After a user opens the page, the browser still has to parse the script and then execute the page code. If the script contains syntax it doesn't support, it throws during parsing. If the code calls a missing method directly, it throws an exception when execution reaches that line. Both kinds of errors can interrupt first-screen rendering and show the user a white screen.
Two separate production exceptions both happened during execution. One occurred when a component was looking up an array element; the other occurred while the client was generating an identifier.
A missing array method causes the page to white-screen
A production record shows the page white-screening in an older browser. The items below stands for the actual object in the error message.
TypeError: items.findLast is not a function
The browser engine doesn't have findLast, and the page didn't load a compatibility implementation before calling it.
Look up a specific feature in a compatibility table
The ECMAScript spec defines the behavior syntax and built-in APIs should have. Engines like V8, SpiderMonkey, and JavaScriptCore each implement these features and ship them with browser releases, so the same feature can be supported at different times across browsers, and early implementations may behave differently.
You can search a feature by name, for example optional chaining or Array.prototype.findLast. The table below lists the first supported versions of these two features in three desktop browsers. Can I Use website
| Feature | Chrome | Firefox | Safari |
|---|---|---|---|
optional chaining ?. |
80 | 74 | 13.1 |
array method findLast |
97 | 104 | 15.4 |
If the product needs to support Chrome 90, ?. can be left to the browser to parse, while findLast needs a compatibility implementation.
For mobile browsers and embedded WebViews, check the engine and version individually; it's also worth reading the partial-support notes in compatibility tables.
Use a polyfill to fill in the array method
Code that supplies a compatibility implementation for a missing or incomplete API is called a polyfill. After the array method is patched in, the component can keep calling items.findLast(...). The same approach works for APIs like Promise.allSettled and URLSearchParams, as long as the environment provides the basic capabilities those implementations need.
The example below demonstrates both findLast, which returns the matching value, and findLastIndex, which returns the index. Save the code as repro.cjs, run node repro.cjs in a directory that has core-js installed, and use a separate process to simulate these two methods being missing.
delete Array.prototype.findLast
delete Array.prototype.findLastIndex
try {
[1, 9, 4].findLast(value => value > 1)
} catch (error) {
console.log(error.name) // TypeError
}
require('core-js/actual/array/find-last')
require('core-js/actual/array/find-last-index')
console.log([1, 9, 4].findLast(value => value > 1)) // 4
console.log([1, 9, 4].findLastIndex(value => value > 1)) // 2
The first call throws a TypeError. After the patch is loaded, the matching value is 4 and its index in the array is 2.
Handwritten patch works on a normal array, fails on another object
Since a reverse loop can find the last match, why not write your own method? The example below runs the handwritten version and the native version against the same inputs. The handwritten version normalizes length with >>> 0, and the example keeps only the search process; it can be run standalone in Node.js that supports findLastIndex.
function findLastIndexFallback(predicate, thisArg) {
const length = this.length >>> 0
for (let index = length - 1; index >= 0; index--) {
if (predicate.call(thisArg, this[index], index, this)) return index
}
return -1
}
const nativeFindLastIndex = Array.prototype.findLastIndex
const items = [1, 9, 4]
const greaterThanOne = value => value > 1
console.log(findLastIndexFallback.call(items, greaterThanOne)) // 2
console.log(nativeFindLastIndex.call(items, greaterThanOne)) // 2
const length = 2 ** 32
const arrayLike = { length, [length - 1]: 'last' }
const matches = value => value === 'last'
console.log(findLastIndexFallback.call(arrayLike, matches)) // -1
console.log(nativeFindLastIndex.call(arrayLike, matches)) // 4294967295
On a normal array, both calls output 2, so testing only this input makes it hard to spot the problem. The array-like object only has length and the property at the last index; there is no need to create billions of elements. findLastIndex can run on this object via .call(), and the native method finds 'last' on the first iteration. The handwritten >>> 0 converts 2 ** 32 to the unsigned 32-bit integer 0, so the loop never runs.
If this handwritten implementation is used as a patch, callers will treat -1 as 'no match found'. This kind of error has a legal return value, so it's harder to notice than an exception. After removing the native method and patching with core-js, the same input still returns 4294967295.
To offer a handwritten function as a standard method, you'd need to cover every input and edge behavior the method accepts. That kind of patching is better left to a mature polyfill backed by a spec and tests. When the business only needs to handle a known set of inputs, you can keep the implementation at the call site and name it with a business-facing function name that expresses the scope it supports.
Load the polyfill before the component's first call
If a first-screen component calls findLast, you can add targeted imports at the client startup entry.
import 'core-js/actual/array/find-last'
import 'core-js/actual/array/find-last-index'
A React SPA can load it before calling createRoot; a Vue SPA can load it before calling createApp(...).mount(...). Next.js App Router can use instrumentation-client.ts; Pages Router can use a top-level import in a custom _app. Which APIs a framework's built-in patches cover depends on the installed version.
| Loading method | Applicable conditions |
|---|---|
| Targeted import at entry | Only a few APIs are missing, or first-screen components already depend on these methods |
| Injected by the build tool | There is a defined set of target browsers. Vite can use @vitejs/plugin-legacy to generate compatible artifacts. Babel 7 can use preset-env with useBuiltIns; Babel 8 can use babel-plugin-polyfill-corejs3 |
| Detect then dynamically load | Only optional features use the method. Detect first, wait for the patch to load, then start the feature |
Even if an old engine can load ES modules, check whether the build plugin covers APIs called by third-party components. Prototype patches on the main page only affect its own execution context; iframe and Worker need separate checks.
A component library can also use local implementations like core-js-pure to be compatible at the call sites it controls. When a published third-party component continues to call a prototype method, the application needs to provide that method before the component runs.
Back on the page, verify the component can render
After simulating the missing method in a recent Chromium and loading these two patches, the affected component rendered again. The real old engine still needs separate verification.
When initialization fails, check the random number interface
Array lookup can be implemented with existing JavaScript capabilities. Generating a UUID v4 also needs trusted random bytes. Another production exception happened during client initialization: the code called crypto.randomUUID() to generate an identifier and immediately threw.
TypeError: crypto.randomUUID is not a function
The record only confirms the method was not callable at that moment; the exact cause still needs to be confirmed. When troubleshooting, first check whether the code is accessing the browser's globalThis.crypto, Node.js's node:crypto, or a browser replacement module chosen by the bundler, then check isSecureContext and method availability in that environment.
Check what other random sources the environment provides
Browsers only expose randomUUID() in secure contexts. If the environment implements getRandomValues(), a plain HTTP page can still use it to get random bytes. When testing HTTP scenarios, distinguish a regular HTTP site from localhost, which is usually treated as a trustworthy origin.
Decide how to degrade based on what the identifier is for
Put the random-source detection into a generator function. The function calls the native method first, or it can hand the random bytes from getRandomValues() to the uuid library. When the function returns undefined, the caller decides whether that operation can continue.
import { v4 as uuidv4 } from 'uuid'
export function createUuid(): string | undefined {
const crypto = globalThis.crypto
if (typeof crypto?.randomUUID === 'function') return crypto.randomUUID()
if (typeof crypto?.getRandomValues === 'function') {
return uuidv4({ random: crypto.getRandomValues(new Uint8Array(16)) })
}
}
| Local simulation condition | Verification result |
|---|---|
Native randomUUID() available |
Uses the native UUID |
Only getRandomValues() |
Generates a UUID v4 from random bytes |
| Both methods missing | Local logs use a temporary identifier; server operations that require a standard UUID stop and explain why |
Local regression also verified that a retry of the same operation reuses the original request identifier. Tokens, keys, and challenge values each have their own secure-random-source requirements.
How cross-platform libraries provide random capability
The same library may run in both the browser and Node.js. A library author can use conditional exports to put Node.js-only dependencies in the corresponding entry, detect the available random source at call time, or accept a random source supplied by the caller. If the random-source requirements and failure results are part of the interface contract, integrators can tell before use whether a path works.
How to decide between transpiling, polyfilling, and degrading
Start by using the error to locate the failed syntax or API, then check the browser or WebView version, the script the page actually received, and where the code executed. TypeScript's lib provides declarations for type checking; whether an API is available must be confirmed in the runtime environment.
| Approach | How to judge | How to handle | How to verify |
|---|---|---|---|
| Transpile syntax | The target browser cannot parse syntax in the published script, for example ?. |
Set the build target so the tool generates code the target browser can parse | Load the actual build artifact in the target browser and confirm the script parses and initializes |
| Polyfill | The script executes, and the missing or incomplete API can be implemented equivalently with existing capabilities, for example findLast |
Choose a polyfill with test coverage and load it into the corresponding execution context before the first call | Check the published artifact contains the patch, simulate the native method missing, and confirm the first call succeeds with a correct result |
| Feature detection and fallback | The feature depends on a capability the environment provides, for example trusted random sources for UUID | Check the capability at runtime. Continue when the alternative path meets the original requirements; otherwise degrade or prompt based on the use case | Test native-capability available, only the alternative available, and neither available; check each path's result and prompt |
The three approaches can be combined. For example, if a page needs to support Chrome 79, the build can transpile ?., and at runtime it can check for findLast and load a polyfill when missing. If the page also needs to generate a UUID, the same detection approach can pick an available random source.
After verifying each path separately, use the same published artifact in the target environment and go from opening the page to performing actual operations, confirming that the first screen renders, features complete, and degraded paths produce the expected result.
References and data sources
- Can I Use optional chaining support table
- Can I Use findLast support table
- MDN polyfill glossary
- ECMAScript Array.prototype.findLast
- ECMAScript Array.prototype.findLastIndex
- core-js Array targeted entries
- core-js global and local usage
- Next.js browser support and polyfills
- Next.js client instrumentation entry
- React createRoot
- Vue browser support
- Vite production build and browser compatibility
- Babel preset-env
- Babel optional chaining transform
- TypeScript lib configuration
- W3C Web Crypto interface
- W3C secure contexts and trustworthy origins
- uuid browser support and random sources
- Node.js package conditional exports
Top 1 from juejin.cn, machine-translated. The original thread is authoritative.
Patch loading order also needs to cover first-screen testing.