hardkoded / puppeteer-sharp

Headless Chrome .NET API
https://www.puppeteersharp.com
MIT License
3.34k stars 439 forks source link

How to check if a request have been handled by interception #1524

Open clement128 opened 4 years ago

clement128 commented 4 years ago

Hi there, this is not a bug but more a question (sorry if it's not a right place to ask here let me know). How can I check if a request have been handled by interception? as per here https://github.com/puppeteer/puppeteer/issues/2687#issuecomment-463922612, puppeteer it have a property named '_interceptionHandled' to use, but seems puppeteer-sharp doesn't provide it.

many thanks

kblok commented 4 years ago

We could expose that property for sure. What would be the use-case scenario?

clement128 commented 4 years ago

Hi @kblok, I have few extension methods for example:

public static async Task DisableImages(this Page page) {
    await page.SetRequestInterceptionAsync(true);
    page.Request += async (sender, args) =>
    {
        if (args.Request.ResourceType == ResourceType.Image) await args.Request.AbortAsync();
        else await args.Request.ContinueAsync();
    }
}
public static async Task DisableStyleSheet(this Page page) { // similar logic}
public static async Task IgnoreUrls(this Page page, params string[] urls) { // similar logic}

I want them separated and combinable on some cases case 1:

var page = await newPageAsync();
await page.DisableImages();
// my business logic

case 2:

var page = await newPageAsync();
await page.DisableImages();
await page.DisableStyleSheet();
// my business logic

case 3:

var page = await newPageAsync();
await page.DisableStyleSheet();
await page.IgnoreUrls("https://www.google.com");
// my business logic
kblok commented 3 years ago

Closed due to inactivity. Feel free to reopen it if needed.

clement128 commented 3 years ago

Hi @kblok I think this is not solve yet? Or do you think these use-case scenario doesn't make sense?

kblok commented 3 years ago

Re-opening. Thanks @clement128 for pushing back.