Cannot read properties of null (reading 'tagName') when using happy-dom
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 11.5k
- Forks
- 732
- PR merge metrics
- No merged PRs in 30d
Description
Hello, I found this issue when parsing some specific HTML markup; I'm not sure what the root cause is.
Reproduction
const { Readability } = require('@mozilla/readability')
const { Browser } = require('happy-dom')
const path = require('path')
const fs = require('fs')
// https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper-readability/test/fixtures/chowhanandsons.com.html
const html = fs.readFileSync(
path.join(__dirname, 'packages/metascraper-readability/test/fixtures/chowhanandsons.com.html'),
'utf-8'
)
const getDocument = ({ url, html }) => {
const browser = new Browser({
settings: {
disableComputedStyleRendering: true,
disableCSSFileLoading: true,
disableIframePageLoading: true,
disableJavaScriptEvaluation: true,
disableJavaScriptFileLoading: true
}
})
const page = browser.newPage()
page.url = url
page.content = html
return {
document: page.mainFrame.document,
teardown: () => browser.close()
}
}
const url = ' https://www.chowhanandsons.com/'
const { document, teardown } = getDocument({ url, html })
const reader = new Readability(document)
console.log(reader.parse())
teardown()
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the failure with packages/metascraper-readability/test/fixtures/chowhanandsons.com.html, happy-dom, and Readability.parse(). Trace the null value to determine why tagName is accessed during parsing. Done means this fixture no longer triggers the TypeError and the behavior is covered by a regression check.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100