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

オープン 初心者向け
#150 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

@FaizanUllahDev がすでに取り組んでいます。

2026年10月29日 から。

  • #152 @FaizanUllahDev による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
82/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
dart, javascript
領域
mobile, web-dev

調査の方向性

lib/assets/no_sleep.js の enable() と _playVideoCompleter の処理から始める。各呼び出しがローカル参照ではなくモジュールレベルの _nativeEnabledCompleter を読み取るため、null に設定され処理済みの completer が次の .then/.catch をクラッシュさせる。issue が提案するローカル参照パターンを両方の completer に適用し、その後 (Safari/web で) WakelockPlus.enable() を待機せずに繰り返し呼び出して検証し、リポジトリのテストスイート (dart test / flutter test) と Web ビルドを実行して、未処理の rejection が残っていないことを確認する。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Dart
スター
110
フォーク
99
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

fluttercommunity/wakelock_plus のほかの issue

fluttercommunity/wakelock_plus の issue をすべて見る

似ている issue

Dart の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。