Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Web: TypeError: null is not an object (evaluating '_nativeEnabledCompleter.completeError') on overlapping enable() calls

Aperta Adatta ai principianti
#150 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
dart, javascript
Ambito
mobile, web-dev

Direzione di ricerca

Parti da lib/assets/no_sleep.js, in enable() e nella gestione di _playVideoCompleter: ogni chiamata legge il _nativeEnabledCompleter a livello di modulo invece di un riferimento locale, quindi un completer già risolto e impostato a null fa crashare il successivo .then/.catch. Applica a entrambi i completers il pattern a riferimento locale suggerito dall'issue, poi verifica chiamando WakelockPlus.enable() ripetutamente senza attendere (Safari/web) ed esegui la suite di test del repo (dart test / flutter test) oltre a una build web per confermare che non rimane alcun rifiuto non gestito.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Version: 1.7.0. The same code is still in main.
Platform: Web, Safari / iOS PWA

Description

In lib/assets/no_sleep.js, all calls to enable() share the module-level _nativeEnabledCompleter. Overlapping enable() calls can end up using the same completer while each sends its own navigator.wakeLock.request('screen'). The first request to settle completes the completer and sets it to null. When the next request settles, its handler calls _nativeEnabledCompleter.completeError(...) on null; on success it calls .complete() instead.

The TypeError is thrown inside a .catch handler of a promise that nothing awaits. Dart code can't catch it, so it surfaces as an unhandled rejection. Our Sentry has about 19K events of it, mostly from Safari, where wakeLock.request often rejects with NotAllowedError.

Steps to reproduce

Call WakelockPlus.enable() several times without awaiting, for example on every route change, in Safari.

Suggested fix

In each enable() call, keep a local reference to the completer and use that reference in .then / .catch, instead of reading the shared variable:

var completer = _nativeEnabledCompleter
navigator.wakeLock.request('screen')
.then(function (wakeLock) { /* ... / completer.complete(); if (_nativeEnabledCompleter === completer) _nativeEnabledCompleter = null })
.catch(function (err) { /
... */ completer.completeError(errorMessage); if (_nativeEnabledCompleter === completer) _nativeEnabledCompleter = null })
return completer.future
_playVideoCompleter is handled the same way and has the same problem.

Workaround

On our side, we now run enable() / disable() one at a time and skip a call when the wakelock is already in the requested state.

Lingua principale
Dart
Stelle
110
Fork
99
Merge medio
9h 27m
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di fluttercommunity/wakelock_plus

Tutte le issue di fluttercommunity/wakelock_plus

Issue simili

Altre issue su Dart

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.