Search code examples
c#puppeteerpuppeteer-sharp

trying to set referer in browser but i get error in puppeteersharp?


I would like to set the referrer to puppeteersharp in c# but I get the error

cannot convert from 'string' to System.Collections.Generic.Dictionary<string, string>

this is my code :

Browser browser = await Puppeteer.LaunchAsync(new LaunchOptions
        {

            Headless = false,
            ExecutablePath = textBox6.Text,

            //Args = { '--start-maximized' },
            Args = new string[]
            {string.Format("--proxy-server={0}",line)}



        });

        // Create a new page and go to Bing Maps
        Page page = await browser.NewPageAsync();
        //await page.GoToAsync("https://music.apple.com/login");
        await page.SetUserAgentAsync("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36");
        await page.SetExtraHttpHeadersAsync("facebook.com");

This is the error that i get : enter image description here


Solution

  • SetExtraHttpHeadersAsync expects a dictionary with the headers to append:

    await Page.SetExtraHttpHeadersAsync(new Dictionary<string, string>
    {
      ["Referer"] = "Bar"
    });