Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
feature(prefer-id-selector)
Browse files Browse the repository at this point in the history
Fixes #32
  • Loading branch information
rationalthinker1 committed Apr 19, 2019
1 parent 58c20e1 commit 1cc71a7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/content-scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class EventRecorder {
this.isTopFrame = (window.location === window.parent.location)
}

start () {
boot () {
// We need to check the existence of chrome for testing purposes
if (chrome.storage && chrome.storage.local) {
chrome.storage.local.get(['options'], ({options}) => {
Expand Down Expand Up @@ -72,9 +72,10 @@ class EventRecorder {
// we explicitly catch any errors and swallow them, as none node-type events are also ingested.
// for these events we cannot generate selectors, which is OK
try {
const optimizedMinLength = (e.target.id) ? 2 : 10 // if the target has an id, use that instead of multiple other selectors
const selector = this.dataAttribute && e.target.hasAttribute && e.target.hasAttribute(this.dataAttribute)
? formatDataSelector(e.target, this.dataAttribute)
: finder(e.target, {seedMinLength: 5, optimizedMinLength: 10})
: finder(e.target, {seedMinLength: 5, optimizedMinLength: optimizedMinLength})

const msg = {
selector: selector,
Expand Down Expand Up @@ -113,4 +114,4 @@ function formatDataSelector (element, attribute) {
}

window.eventRecorder = new EventRecorder()
window.eventRecorder.start()
window.eventRecorder.boot()

0 comments on commit 1cc71a7

Please sign in to comment.