Opened on 04/26/2018 at 04:25:56 AM

#6629 new defect

How to use libadblockplus?

Reported by: Alecyrus Assignee:
Priority: Unknown Milestone:
Module: Unknown Keywords:
Cc: Blocked By:
Blocking: Platform: Unknown / Cross platform
Ready: no Confidential: no
Tester: Unknown Verified working: no
Review URL(s):

Description

I really need someone who can help me that will be very grateful.
I had read carefully the source code of Abpshell (The demo application in the libadblock program), but I didn't know how to use matches() fucton and GetElementHidingSelectors() function. I even don't know what documentUrls is , How I get the documentUrl.
The application I develop is advertisement Identifier that can split the ad html section and ad urls from target page. I will be very thankful if someone can offer me some suggestions.

Environment

mac OS X 10.13
XCode 9.3

The latest version of libadblockpuls from Github.

Subscriptions:
EasyList

How to reproduce

My code:

int main(int argc, const char * argv[]) {
    std::cout << "Initialize the JS engine...";
    AdblockPlus::AppInfo appInfo;
    appInfo.version = "1.0";
    appInfo.name = "abpshell";
    appInfo.application = "standalone";
    appInfo.applicationVersion = "1.0";
    appInfo.locale = "en-US";

    auto platform = AdblockPlus::DefaultPlatformBuilder().CreatePlatform();
    platform->SetUpJsEngine(appInfo);
    auto& filterEngine = platform->GetFilterEngine();
    std::cout << "success\n";

    
    Subscription subscription = filterEngine.GetSubscription("https://easylist-downloads.adblockplus.org/easylist.txt");
    subscription.AddToList();
    if (subscription.IsListed()) {
        std::cout << "Imported successfully!\n";
    }
    subscription.UpdateFilters();
    
    cout<<"\nSubscription::\n";
    ShowSubscriptionList(filterEngine.GetListedSubscriptions());
    
    cout<<endl<<"AAURL:"<<filterEngine.GetAAUrl();

    if(filterEngine.IsAAEnabled ()) std::cout << " ...AA enabled!\n";
    else {
        filterEngine.SetAAEnabled(true);
        if(filterEngine.IsAAEnabled ()) std::cout << " AA renabled!\n\n";
    }
    
    cout<<"Test element selector:";
    std::vector<std::string> selectors = filterEngine.GetElementHidingSelectors("google.ru");
    
    cout<<"The number of selectors: "<<selectors.size()<<endl<<endl;
    
    for (auto it = selectors.begin();
         it != selectors.end(); it++)
        std::cout <<*it<< std::endl;
    
    
    
    cout<<endl<<"Test request:";
    filterEngine.GetFilter("adbanner.gif").AddToList();
    FilterPtr match_1 = filterEngine.Matches("http://example.org/adbanner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "");
    if (!match_1){
        std::cout << "No match" << std::endl;}
    else if (match_1->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION)
        std::cout << "Whitelisted by " << match_1->GetProperty("text").AsString() << std::endl;
    else
    {std::cout << "Blocked by " << match_1->GetProperty("text").AsString() << std::endl;}
    
    cout<<endl<<"Test element hiding:";
    FilterPtr match = filterEngine.Matches("http://simple-adblock.com/adblocktest/files/elementhide.html", AdblockPlus::FilterEngine::CONTENT_TYPE_ELEMHIDE, "");

    if (!match){
        std::cout << "No match" << std::endl;}
    else if (match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION)
        std::cout << "Whitelisted by " << match->GetProperty("text").AsString() << std::endl;
    else
    {std::cout << "Blocked by " << match->GetProperty("text").AsString() << std::endl;}
  
    
    return 0;
}

...

Observed behaviour

Output:

Initialize the JS engine...success
Imported successfully!

Subscription::
EasyList - https://easylist-downloads.adblockplus.org/easylist.txt
https://easylist-downloads.adblockplus.org/exceptionrules.txt - https://easylist-downloads.adblockplus.org/exceptionrules.txt
https://easylist-downloads.adblockplus.org/easylistchina.txt - https://easylist-downloads.adblockplus.org/easylistchina.txt

AAURL:https://easylist-downloads.adblockplus.org/exceptionrules.txt ...AA enabled!
Test element selector:The number of selectors: 0


Test request:Blocked by adbanner.gif

Test element hiding:No match
Program ended with exit code: 0

Expected behaviour

How to reproduce
disable AA exceptions subscription (the link above)
invoke filterEngine.getElementHidingSelectors(..) for "google.ru" and get 17387 selectors. make sure ads is NOT shown for "iphone 6 plus" request in google.ru
enable AA by adding subscription (the link above)
invoke filterEngine.getElementHidingSelectors(..) for "google.ru" and get 17388 selectors. make sure ads is NOT shown for the request above.

from https://issues.adblockplus.org/ticket/4473

The number of selectors shouldn't be zero..

Attachments (0)

Change History (0)

Add Comment

Modify Ticket

Change Properties
Action
as new .
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from (none).
Next status will be 'reviewing'.
 
Note: See TracTickets for help on using tickets.