-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Chrome recorder generated selectors (#148)
- Loading branch information
1 parent
49a23b9
commit 98849da
Showing
18 changed files
with
661 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,65 @@ | ||
/* global chrome */ | ||
chrome.devtools.panels.create('Autoconsent', '/icons/cookie.png', "/devtools/panel.html") | ||
chrome.devtools.panels.create( | ||
"Autoconsent", | ||
"/icons/cookie.png", | ||
"/devtools/panel.html" | ||
); | ||
|
||
if (chrome.devtools?.recorder) { | ||
class MyPlugin { | ||
stringify(recording) { | ||
const autoconsentSteps = recording.steps | ||
.filter((step) => ["click"].includes(step.type)) | ||
.map(({ selectors }) => this.convertStep(selectors)); | ||
return Promise.resolve(JSON.stringify(autoconsentSteps, undefined, 4)); | ||
} | ||
stringifyStep(step) { | ||
return Promise.resolve( | ||
JSON.stringify( | ||
this.convertStep(step.selectors), | ||
undefined, | ||
4 | ||
) | ||
); | ||
} | ||
convertStep(selectors) { | ||
return { | ||
any: selectors.filter((s) => { | ||
return this.isSupportedSelector(s) | ||
}).map(s => { | ||
if (s.length === 1) { | ||
return { | ||
waitForThenClick: s[0] | ||
} | ||
} | ||
return { | ||
waitForThenClick: s | ||
} | ||
}) | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* @param {string | string[]} selector | ||
* @returns | ||
*/ | ||
isSupportedSelector(selector) { | ||
const unsupportedPrefixes = ['aria/', 'pierce/', 'text/'] | ||
if (!Array.isArray(selector)) { | ||
return !unsupportedPrefixes.some(p => selector.startsWith(p)) | ||
} | ||
// Chained xpath selectors are not supported | ||
if (selector.length > 1 && selector.some(s => s.startsWith('xpath/'))) { | ||
return false | ||
} | ||
return selector.every(s => this.isSupportedSelector(s)) | ||
} | ||
} | ||
|
||
chrome.devtools.recorder.registerRecorderExtensionPlugin( | ||
new MyPlugin(), | ||
/*name=*/ "Autoconsent", | ||
/*mediaType=*/ "application/json" | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.