2
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?

型 "new"を型 'boolean | "shell" | undefined' に割り当てることはできません

Posted at

はじめに

puppeteerを使用している中で設定した型にエラーが出ました。

const browser = await puppeteer.launch({
            headless: 'new'
 });

エラー内容:
型 '"new"' を型 'boolean | "shell" | undefined' に割り当てることはできません

エラー原因

puppeteerの型定義でheadlessオプションが以下の型を受け付けると定義されていて、今回の"new"はどれにも該当しなかったため発生したエラーのようです。

- boolean: true/false
- "shell": 文字列の"shell"
- undefined: 未定義

以下の公式ドキュメントでは設定変更のオプションが記載されています。
https://developer.chrome.com/docs/chromium/headless?hl=ja

const browser = await puppeteer.launch({
  headless: 'true', // (default) enables Headless
  // `headless: 'old'` enables old Headless
  // `headless: false` enables "headful" mode
});

ここに設定する値でHeadlessの有効化・無効化をすることが可能なようです。

解決策

最終的に今回のコードは以下のようにHeadlessを有効化させて解決ができました。

const browser = await puppeteer.launch({
      headless: true // 'new'から`true`に変更
});

おわりに

はじめて使うライブラリなので公式ドキュメントを確認しつつ進めるのが一番いいのかもしれないと気づくきっかけになりました。

2
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
2
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?