5

Javascript gives error: "DOMException: Failed to read the 'cookie' property from 'Document': Access is denied for this document."

Iv'e set all cookies to use use HttpOnly = false but it do not seem to help. The page works perfectly if I call the page without puppeteer.

I currently copy all session variables from the request I am initializing puppeteer with:

var cookies = new List<CookieParam>();

foreach (var key in request.Cookies.Keys)
{
    var cookie = request.Cookies.Get(key.ToString());

    cookies.Add(new CookieParam {
        Name = cookie.Name,
        Value = cookie.Value,
        HttpOnly = false,
        Domain = cookie.Domain,
        Url = baseUrl,
        Path = cookie.Path,
        Secure = cookie.Secure
    });
}

await page.SetCookieAsync(cookies.ToArray());
Blue
  • 81
  • 5

1 Answers1

3

I were using page.SetContent(...) to create the page content. This do not seem to allow usage of cookies client side.

I switched to use page.GoToAsync(...) which avoided the problem.

Blue
  • 81
  • 5