Skip to content

Page cookies in the callback #339

@Ehsan-U

Description

@Ehsan-U

Is it possible to access the playwright cookies in the callback without passing the page itself ? it can be accessed by storing into global variable but that could cause issues in case of multiple pages.
It would be very useful to have the page cookies in the callback.

    def start_requests(self) -> Iterable[Request]:
        url = "https://corp.sec.state.ma.us/CorpWeb/CorpSearch/CorpSearch.aspx"
        yield scrapy.Request(url, callback=self.parse, meta={
            "playwright": True,
            "playwright_page_methods": [
                PageMethod(self.init_session)
            ]
        })

    async def init_session(self, page: Page) -> None:
        cookies = await page.context.cookies()
        return cookies
    
    def parse(self, response: Response):
        # how to access playwright cookies here, 
        pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions