前提・実現したいこと
Node.jsとpuppeteerで「現在のURL」を取得したいです。
Node.js、2日目でまだ途方に暮れています。
よろしくお願いします。
発生している問題・エラーメッセージ
(node:7496) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'href' of undefined (node:7496) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
該当のソースコード
javascript
1'use strict'; 2 3const puppeteer = require('puppeteer'); 4 5(async() => { 6 const browser = await puppeteer.launch(); 7 const page = await browser.newPage(); 8 await page.goto('https://www.youtube.com/results?search_query='+ 'Lemon'); 9 console.log(page.location.href);
補足情報(FW/ツールのバージョンなど)
Windows 10
Node.js
https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pageurl
を見たところ、page.url();でとれそうなのですが、これは最初に開いたurlで、現在のurlではありませんでした。取得したいのは、現在のurlです。