Rayrun
← Back to Discord Forum

how can i send request OPTIONS with playwright?

please help me

This thread is trying to answer question "How can I send an OPTIONS request with Playwright and access local storage?"

43 replies
insanerookstar
insanerookstar

Use .fetch({ method: 'options' })

thank you

lets me check

@insanerookstar can i access local storage?

insanerookstar
insanerookstar

through evaluation

my code is correct?

browser = await playwright.chromium.launch() context = await browser.new_context(base_url="my_url") api_request_context = context.request res = await api_request_context.fetch( "", method="options", ) res=await api_request_context.storage_state() print(res) await browser.close()

Please help me

insanerookstar
insanerookstar

just run the code

insanerookstar
insanerookstar

and check it on your own

I checked the code

But return empty value

For cookie and origins

insanerookstar
insanerookstar
res = await api_request_context.fetch(
        "",
        method="options",
      )
    res=await api_request_context.storage_state()
insanerookstar
insanerookstar

you assign two values to the same variable

insanerookstar
insanerookstar

may it be the problem?

I dont think so

insanerookstar
insanerookstar

and why do you assume that storage state should not be empty at this moment?

Cuz i used my browser

Then its still return correct value

In local storage

insanerookstar
insanerookstar

in the code you just created the context, maybe you should open the page and then check the storage state?

@qdvbp: You can see

You can see

Browser.new_context

Its mean open the page?

insanerookstar
insanerookstar

but APIRequestContext may not have the access to the localstorage

insanerookstar
insanerookstar
@qdvbp: its just the context and the context can have multiple pages assigned to it

its just the context and the context can have multiple pages assigned to it

insanerookstar
insanerookstar

in js its const page = await context.newPage()

insanerookstar
insanerookstar

and then await page.goto('/')

@insanerookstar: how do you think about still return correct status code `204` when i send `options` request?

how do you think about still return correct status code 204 when i send options request?

res = await api_request_context.fetch( "", method="options", ) res=await api_request_context.storage_state()

i think its still correctly request?

insanerookstar
insanerookstar

why not

i try send other methods to my url

then return 404

my url return 204 when send options

and return code 200 when send post

page=await context.new_page() session_storage = await page.evaluate("localStorage")

then i got Failed to read the 'localStorage' property from 'Window': Access is denied for this document.

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].