Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create focus-without-user-activation.md #304

Merged
merged 5 commits into from
May 22, 2019
Merged

Conversation

ehsan-karamad
Copy link
Contributor

Add an explainer for focus-without-user-activation policy which helps reduce abusing automatic focus in embedded contents.

Add an explainer for `focus-without-user-activation` policy which helps reduce abusing automatic focus in embedded contents.
```HTTP
Feature-Policy: focus-without-user-activation 'none'
```
would cause all all automatic focus in the page (and neste contexts) to fail unless it has been

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant "all", "neste" -> "nested".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!


To disable the feature for a specific `<iframe>`, the `allow` attribute can be used:
```HTTP
Feature-Policy: focus-without-user-activation 'self'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there an intention to provide an example with <iframe allow="..">? Maybe it got lost when copy/pasting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an example.

To avoid unnecessary breakage of existing contents, disabling the focus should still let parts of
the [focus update steps](https://html.spec.whatwg.org/multipage/interaction.html#focus-update-steps)
run. In a nutshell:
* The `activeElement` of the blocked document should be updated. All the focus related events

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not en expert on focus behavior in browsers, but does that mean that activeElement would be updated even though it actually would not be active?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a bit hand-wavy and I still need to dig through the steps in the spec, but what I am suggesting is that the document inside the <iframe> that is blocked shouldn't know about the focus not really working. I wonder if it makes sense for all the steps in focus work (inside the <iframe>) but not make it target for keyboard input (focusable area).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what would be the best approach. But out of curiosity: Would you want the document not to know about focus being blocked for security reasons? Anyway, PR looks good to me.

Added an example for allow.
Make focus blocking explicit in the steps of `autofocus`, `window.focus()` and `element.focus()`.
Copy link

@marian-r marian-r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found some typos 🙂

* Around step 4 of the [spec](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autofocus for `autofocus` the algorithm should return if the policy `focus-without-user-activation` is disabled and the algorithm is not
[triggered by user activation](https://html.spec.whatwg.org/multipage/interaction.html#triggered-by-user-activation).
* Before starting [steps](https://html.spec.whatwg.org/multipage/interaction.html#dom-window-focus) for `element.focus(options)` the same verification for the policy and user activation should be performed.
* Aroudn step 2 of the the [spec](https://html.spec.whatwg.org/multipage/interaction.html#dom-window-focus) for `window.focus()` the same enforcement should be made (using the browsing context of the `window` itself to obtaint he feature policy state.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aroundn -> Around, obtaint he -> obtain the, closing parentheses at the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks you! I fixed those two and also updated the focus algorithm link (update focus steps -> focusing steps).

Fixed some typos and updated the link to focus algorithm in the spec.
Copy link

@marian-r marian-r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@clelland clelland merged commit 5fc9b58 into w3c:master May 22, 2019
@JSteunou
Copy link

Can't wait to see this flag usable everywhere :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants