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

Rewritten_url returns null #400

Open
toxin-x opened this issue Nov 5, 2024 · 1 comment
Open

Rewritten_url returns null #400

toxin-x opened this issue Nov 5, 2024 · 1 comment

Comments

@toxin-x
Copy link

toxin-x commented Nov 5, 2024

i am trying to make a link filter using this list but I can't seem to get the rewritten url, here is my code along with what i expect. Am i missing something to enable removeparam in the docs?

import adblockRust from 'adblock-rs';
import fs from 'node:fs';
const dataPath = './data/adblock-rust-master/data/'

const debugInfo = true;
const filterSet = new adblockRust.FilterSet(debugInfo);

const shortenerFilters = fs.readFileSync(
    'LegitimateURLShortener.txt',
    { encoding: 'utf-8' },
).split('\n');
filterSet.addFilters(shortenerFilters);
console.log(shortenerFilters[0])

// const easylistFilters = fs.readFileSync(
//     dataPath + 'easylist.to/easylist/easylist.txt',
//     { encoding: 'utf-8' },
// ).split('\n');
// filterSet.addFilters(easylistFilters);

const uboUnbreakFilters = fs.readFileSync(
    dataPath + 'uBlockOrigin/unbreak.txt',
    { encoding: 'utf-8' },
).split('\n');
filterSet.addFilters(uboUnbreakFilters);

const resources = adblockRust.uBlockResources(
    dataPath + 'test/fake-uBO-files/web_accessible_resources',
    dataPath + 'test/fake-uBO-files/redirect-resources.js',
    dataPath + 'test/fake-uBO-files/scriptlets.js'
);

const engine = new adblockRust.Engine(filterSet, true);
engine.useResources(resources);

console.log(engine.check(
    'https://www.amazon.com/National-Geographic-Hobby-Rock-Tumbler/dp/B01LQCIL88/?_encoding=UTF8&pd_rd_w=a88WT&content-id=amzn1.sym.12c47663-8a7e-43d5-9c0a-9fb1870a90c3&pf_rd_p=12c47663-8a7e-43d5-9c0a-9fb1870a90c3&pf_rd_r=3BKDDFN4AJ4N5805MMKF&pd_rd_wg=JVspV&pd_rd_r=da0cab95-d366-49ed-a9a9-52f9a277bf62&ref_=pd_hp_d_atf_dealz_cs',
    'https://amazon.com',
    'html',
    true

));

result:

! Title: ➗ Actually Legitimate URL Shortener Tool
{
  matched: false,
  important: false,
  redirect: null,
  rewritten_url: null,
  exception: null,
  filter: null
}

expected:

! Title: ➗ Actually Legitimate URL Shortener Tool
{
  matched: True,
  important: false,
  redirect: null,
  rewritten_url: 'https://www.amazon.com/National-Geographic-Hobby-Rock-Tumbler/dp/B01LQCIL88/?_encoding=UTF8',
  exception: null,
  filter: null
}

thank you!

@antonok-edm
Copy link
Collaborator

@toxin-x you're using 'html' as the request type, which isn't valid. You can find the full list of request types here. I assume you want to use 'document'; When I do so, I get the following:

{
  matched: false,
  important: false,
  redirect: null,
  rewritten_url: 'https://www.amazon.com/National-Geographic-Hobby-Rock-Tumbler/dp/B01LQCIL88/?_encoding=UTF8&pd_rd_w=a88WT&pf_rd_p=12c47663-8a7e-43d5-9c0a-9fb1870a90c3&pf_rd_r=3BKDDFN4AJ4N5805MMKF&pd_rd_wg=JVspV&pd_rd_r=da0cab95-d366-49ed-a9a9-52f9a277bf62&ref_=pd_hp_d_atf_dealz_cs',
  exception: null,
  filter: null
}

Does that look how you'd expect?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants