Skip to content

Question About Fetching Browser's Timezone #3096

Answered by falkoschindler
daya0576 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @daya0576,

This looks like issue #2520 which is still unresolved. As a workaround you can await the client connection in your page function(s) like this:

async def get_or_create_user_timezone() -> None:
    timezone = await ui.run_javascript("Intl.DateTimeFormat().resolvedOptions().timeZone")
    print(f"User timezone: {timezone}")
    app.storage.user["timezone"] = timezone


@ui.page('/')
async def page():
    await ui.context.client.connected()
    await get_or_create_user_timezone()
    ui.label('Hello, world!')

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by daya0576
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants