1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-05 05:17:40 +02:00
bitwarden-browser/apps/browser
Rafael Kraut 208be8dfbf
[PS-1918] Make autofill doc-scanner traverse into ShadowRoot (#4119)
* This commit implements the following main changes:

- Query elements by using a TreeWalker instead of `document.querySelector[All]`. The reason for this is that `querySelector[All]` doesn't traverse into elements with ShadowRoot.
- Recursively traverse into elements with `openOrClosedShadowRoot` or `Element.shadowRoot` (depending on browser support) inside TreeWalker loop.
- Use new query logic everywhere inside `autofill.js`. This also means we need to use filter functions to find elements with specific nodeNames and/or attributes instead of CSS selector strings.
- Add two new `instanceof Element` checks to prevent `Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'." errors`.

This change is fully backward compatible. If `openOrClosedShadowRoot` is not available it will always return undefined and we will never traverse into ShadowRoots just as the behavior was before this change.

* refactor: outsource recursive logic to accumulatingQueryDocAll

We don't want the `els` argument on the `queryDocAll` function because it's never used from outside the function itself. Thus the recursive logic is moved to `accumulatingQueryDocAll`.
Now `queryDocAll` creates an empty array and passes it to `accumulatingQueryDocAll` which recursively walks the document and all ShadowRoots and pushes all found nodes directly to the referenced array.

The decision to use a directly mutated array instead of `Array.concat(els)` or `Array.push(...els)` is for performance reasons. Pushing to the referenced array was 74% faster than using `Array.push` with spread operator and even 90% faster than using `Array.concat`.

Co-authored-by: Chad Miller <64046472+chadm-sq@users.noreply.github.com>

* refactor: extract input field relevance check into own function

Addresses CodeScene analysis violation "Bumpy Road Ahead" where conditional logic is checked for a nesting of 2 or deeper.

* refactor: use proper element attribute handling

- use el.type attribute instead of el.attribute.type on input elements. This makes sure we also get 'text' when type attribute is not explicitly specified
- use el.htmlFor attribute instead of el.attribute.for on label elements
- use `hasAttribute` and `getAttribute` methods instead of `attributes[]` which is discouraged by https://quirksmode.org/dom/core/#attributes
- improve readability of `isRelevantInputField`

---------

Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com>
Co-authored-by: Chad Miller <64046472+chadm-sq@users.noreply.github.com>
Co-authored-by: Thomas Rittson <trittson@bitwarden.com>
2023-02-20 08:43:18 +10:00
..
.vscode Multi root workspace tweaks (#2858) 2022-06-13 21:39:36 -05:00
config Login Flows (#4411) 2023-02-05 10:57:21 -05:00
src [PS-1918] Make autofill doc-scanner traverse into ShadowRoot (#4119) 2023-02-20 08:43:18 +10:00
store Autosync the updated translations (#4711) 2023-02-15 11:17:30 +01:00
.gitignore Simplify our gitignore files (#2925) 2022-06-17 15:33:51 +02:00
crowdin.yml Fix Crowdin Pull workflow (#2667) 2022-05-10 10:20:32 -04:00
gulpfile.js [Desktop/Browser] - Renew signing certificates (#4739) 2023-02-13 15:49:03 -07:00
jest.config.js [EC-423] Fix unit tests (#3265) 2022-08-11 11:35:08 +10:00
package.json Bumped browser version to 2023.2.1 (#4783) 2023-02-16 17:30:14 +00:00
README.md Update urls to match the contributing docs (#4192) 2022-12-06 11:20:27 +01:00
test.setup.ts [PS-1306] Context Menu for MV3 (#3910) 2023-01-06 19:31:32 -05:00
tsconfig.json [SM-252] Enable strict templates (#3601) 2022-11-28 18:59:46 +01:00
tsconfig.spec.json [EC-423] Fix unit tests (#3265) 2022-08-11 11:35:08 +10:00
webpack.config.js [CSA-28] Use path normalization in API requests (#4580) 2023-02-03 14:24:49 -05:00

Github Workflow build browser on master Crowdin Join the chat at https://gitter.im/bitwarden/Lobby

Bitwarden Browser Extension

The Bitwarden browser extension is written using the Web Extension API and Angular.

My Vault

Documentation

Please refer to the Browser section of the Contributing Documentation for build instructions, recommended tooling, code style tips, and lots of other great information to get you started.