1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Firefoxのcanvas操作でNS_ERROR_NOT_INITIALIZEDが出る場合の対処方法

Posted at

canvasの操作でNS_ERROR_NOT_INITIALIZEDが出る場合

備忘録として残します。

エラーが出る処理

ここではCanvasからcaptureStreamでMediaStreamを取得しています。

const canvas = document.getElementById('canvas');
const video = document.getElementById('video');
video.srcObject = canvas.captureStream();       /* ここでエラーがでる */

実行結果

Browser 結果
Chrome OK
Edge OK
Firefox NS_ERROR_NOT_INITIALIZED
Safari OK

回避方法

getContext('2d')の行を追加します。
この処理を入れてもほかのブラウザに影響はありません。

const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');            /* この行を追加 */
const video = document.getElementById('video');
video.srcObject = canvas.captureStream();
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?