Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NodeJS bindings issue #304

Closed
antonok-edm opened this issue Aug 9, 2023 · 0 comments · Fixed by #305
Closed

NodeJS bindings issue #304

antonok-edm opened this issue Aug 9, 2023 · 0 comments · Fixed by #305
Assignees
Labels
bug Something isn't working

Comments

@antonok-edm
Copy link
Collaborator

Unclear why, but there's some bizarre issue in Node where awaiting a fetch changes the behavior of unrelated code later on. In this case it's causing intoContentBlocking to return an object with fields that are undefined.

package.json

{
  "type": "module",
  "dependencies": {
    "adblock-rs": "^0.7.17"
  }
}

index.js

import { FilterSet, FilterFormat, RuleTypes } from 'adblock-rs'
import { readFileSync } from 'fs'

// This line causes the returned fields from `intoContentBlocking` to be `undefined`.
// Everything works as expected when it's commented out.
await fetch("https://easylist-downloads.adblockplus.org/liste_ar.txt").then(r => r.text())

// ...even though we're using rules from disk (the fetch result is unused).
let rules2 = readFileSync('./Liste_AR.txt', 'utf8').trim().split('\n')

const filterSet = new FilterSet(true)
filterSet.addFilters(rules2, { format: FilterFormat.STANDARD, rule_types: RuleTypes.NETWORK_ONLY })
const { contentBlockingRules, filtersUsed } = filterSet.intoContentBlocking()

// logs `undefined undefined`
console.log(typeof contentBlockingRules, typeof filtersUsed)

There's some weird dependency between the rules used and the network request (I can't reproduce it using localhost or my personal website). Based on some poking around at this code, my guess is that the issue exists somewhere in neon-serde, although the fact that the fetch is able to affect the later operations smells like a node bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant