TypeError: Cannot read properties of null (reading 'parentFrame') #895
sasa-andjelic-nqode
started this conversation in
Bugs
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have Browsershot 4.3.0
I use it to evaluate some additional JS on an existing HTML in the following manner:
In the example above I just placed a simple return because of simplicity. In realistic scenario I have a lot more code here.
The problem I am having is that sometimes this works properly but sometimes it fails with the following error:
================ Error Output: ================ /home/vagrant/code/XXXXXXXXXX/vendor/spatie/browsershot/bin/browser.cjs:142 if (response.request().isNavigationRequest() && response.request().frame().parentFrame() === null) { ^ TypeError: Cannot read properties of null (reading 'parentFrame') at /home/vagrant/code/XXXXXXXXXX/vendor/spatie/browsershot/bin/browser.cjs:142:87 at /home/vagrant/node_modules/puppeteer-core/lib/cjs/third_party/mitt/mitt.js:62:7 at Array.map (<anonymous>) at Object.emit (/home/vagrant/node_modules/puppeteer-core/lib/cjs/third_party/mitt/mitt.js:61:20) at CdpPage.emit (/home/vagrant/node_modules/puppeteer-core/lib/cjs/puppeteer/common/EventEmitter.js:83:23) at /home/vagrant/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/Page.js:174:18 at /home/vagrant/node_modules/puppeteer-core/lib/cjs/third_party/mitt/mitt.js:62:7 at Array.map (<anonymous>) at Object.emit (/home/vagrant/node_modules/puppeteer-core/lib/cjs/third_party/mitt/mitt.js:61:20) at NetworkManager.emit (/home/vagrant/node_modules/puppeteer-core/lib/cjs/puppeteer/common/EventEmitter.js:83:23) Node.js v21.6.0
So it turned out I was being hit by Demeter in browser.cjs on line because
response.request().frame()
was returning null:if (response.request().isNavigationRequest() && response.request().frame().parentFrame() === null)
When I add a condition to check the frame() before reaching for parentFrame() I get no more random falures.:
if (response.request().isNavigationRequest() && (!response.request().frame() || response.request().frame().parentFrame() === null))
I haven't went deeper into the code to understand to the full extent what is actually going on under the hood, so my question to someone who does understand -> Is this a good solution or would it cause other unforeseen problems?
Beta Was this translation helpful? Give feedback.
All reactions