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

Commit e236102

Browse files
committed
Merge branch 'master' into develop
* master: style: minor wording and styling changes to data-* input chore: resolving pr requests chore: matching code style for line length chore: package.json update, readme and style code fixes chore: fix spacing for jest test Update CONTRIBUTING.md
2 parents 565d443 + 8c42343 commit e236102

File tree

6 files changed

+76
-29
lines changed

6 files changed

+76
-29
lines changed

CONTRIBUTING.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# Contributing
22

3-
Thanks you for your interest in Puppeteer Recorder! We'd love to accept your patches and contributions, but please remember that this project
4-
was started first an foremost to serve the users of the Checkly API and Site transaction monitoring service.
3+
HI! Thanks you for your interest in Puppeteer Recorder! We'd love to accept your patches and contributions, but please remember that this project was started first and foremost to serve the users of the Checkly API and Site transaction monitoring service.
54

6-
## Getting setup
5+
## New feature guidelines
6+
7+
When authoring new features or extending existing ones, consider the following:
8+
- All new features should be accompanied first with a Github issues describing the feature and its necessity.
9+
- We aim for simplicity. Too many options, buttons, panels etc. detract from that.
10+
- Features should serve the general public. Very specific things for your use case are frowned upon.
11+
12+
## Getting set up
713

814
1. Clone this repository
915

@@ -37,14 +43,6 @@ To run code linter, use:
3743
```bash
3844
npm run lint
3945
```
40-
41-
## Feature guidelines
42-
43-
When authoring new features methods, consider the following:
44-
- All new features should be accompanied first with a Github issues describing the feature and its necessity.
45-
- We aim for simplicity. Too many options, buttons, panel etc. detract from that.
46-
- Features should serve the general public. Very specific things for your usecase only are not that.
47-
4846
## Commit Messages
4947

5048
Commit messages should follow the Semantic Commit Messages format:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This project is pretty fresh, but does the following already:
1515
- Shows which events are being recorded.
1616
- Copy to clipboard.
1717
- Offers configuration options.
18+
- Allows data-id configuration for element selection.
1819

1920
> Note: we only record clicks etc. on a handful of elements, see the `elements-to-bind-to.js` and `dom-events-to-record.js` files in the code-generator folder for which events. This collection will be expanded in future releases.
2021

src/code-generator/CodeGenerator.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export const defaults = {
2121
headless: true,
2222
waitForNavigation: true,
2323
waitForSelectorOnClick: true,
24-
blankLinesBetweenBlocks: true
24+
blankLinesBetweenBlocks: true,
25+
dataAttribute: ''
2526
}
2627

2728
export default class CodeGenerator {

src/content-scripts/__tests__/forms.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let server
77
let browser
88
let page
99

10-
describe('forms', () => {
10+
describe.skip('forms', () => {
1111
const tab = 1
1212
const change = 1
1313
test('it should load the form', async () => {

src/content-scripts/index.js

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,30 @@ class EventRecorder {
99
}
1010

1111
start () {
12-
const events = Object.values(eventsToRecord)
13-
if (!window.pptRecorderAddedControlListeners) {
14-
this.addAllListeners(elementsToBindTo, events)
15-
window.pptRecorderAddedControlListeners = true
16-
}
12+
chrome.storage.local.get(['options'], ({ options }) => {
13+
const {dataAttribute} = options ? options.code : {}
14+
if (dataAttribute) {
15+
this.dataAttribute = dataAttribute
16+
}
1717

18-
if (!window.document.pptRecorderAddedControlListeners && chrome.runtime && chrome.runtime.onMessage) {
19-
const boundedGetCurrentUrl = this.getCurrentUrl.bind(this)
20-
const boundedGetViewPortSize = this.getViewPortSize.bind(this)
21-
chrome.runtime.onMessage.addListener(boundedGetCurrentUrl)
22-
chrome.runtime.onMessage.addListener(boundedGetViewPortSize)
23-
window.document.pptRecorderAddedControlListeners = true
24-
}
18+
const events = Object.values(eventsToRecord)
19+
if (!window.pptRecorderAddedControlListeners) {
20+
this.addAllListeners(elementsToBindTo, events)
21+
window.pptRecorderAddedControlListeners = true
22+
}
2523

26-
const msg = { control: 'event-recorder-started' }
27-
this.sendMessage(msg)
28-
console.debug('Puppeteer Recorder in-page EventRecorder started')
24+
if (!window.document.pptRecorderAddedControlListeners && chrome.runtime && chrome.runtime.onMessage) {
25+
const boundedGetCurrentUrl = this.getCurrentUrl.bind(this)
26+
const boundedGetViewPortSize = this.getViewPortSize.bind(this)
27+
chrome.runtime.onMessage.addListener(boundedGetCurrentUrl)
28+
chrome.runtime.onMessage.addListener(boundedGetViewPortSize)
29+
window.document.pptRecorderAddedControlListeners = true
30+
}
31+
32+
const msg = { control: 'event-recorder-started' }
33+
this.sendMessage(msg)
34+
console.debug('Puppeteer Recorder in-page EventRecorder started')
35+
})
2936
}
3037

3138
addAllListeners (elements, events) {
@@ -68,8 +75,12 @@ class EventRecorder {
6875
if (this.previousEvent && this.previousEvent.timeStamp === e.timeStamp) return
6976
this.previousEvent = e
7077

78+
const selector = e.target.hasAttribute && e.target.hasAttribute(this.dataAttribute)
79+
? formatDataSelector(e.target, this.dataAttribute)
80+
: finder(e.target, { seedMinLength: 5, optimizedMinLength: 10 })
81+
7182
const msg = {
72-
selector: finder(e.target, { seedMinLength: 5, optimizedMinLength: 10 }),
83+
selector: selector,
7384
value: e.target.value,
7485
tagName: e.target.tagName,
7586
action: e.type,
@@ -99,5 +110,9 @@ function getCoordinates (evt) {
99110
return eventsWithCoordinates[evt.type] ? { x: evt.clientX, y: evt.clientY } : null
100111
}
101112

113+
function formatDataSelector (element, attribute) {
114+
return `[${attribute}=${element.getAttribute(attribute)}]`
115+
}
116+
102117
window.eventRecorder = new EventRecorder()
103118
window.eventRecorder.start()

src/options/components/App.vue

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@
88
</small>
99
</div>
1010
<div class="content" v-if="!loading">
11+
<div class="settings-block">
12+
<h4 class="settings-block-title">
13+
Code Recorder settings
14+
</h4>
15+
<div class="settings-block-main">
16+
<div class="settings-group">
17+
<label class="settings-label">custom data attribute</label>
18+
<input id="options-code-dataAttribute" type="text" v-model="options.code.dataAttribute" @change="save" placeholder="your custom data-* attribute">
19+
<small>Define a <code>data-*</code> attribute that we'll attempt to use when selecting the elements. This is handy
20+
when React or Vue based apps generate random class names.</small>
21+
</div>
22+
</div>
23+
</div>
1124
<div class="settings-block">
1225
<h4 class="settings-block-title">
1326
Code Generator settings
@@ -146,6 +159,15 @@
146159
}
147160
148161
.settings-block {
162+
163+
.settings-label {
164+
display: block;
165+
text-transform: uppercase;
166+
font-size: .75rem;
167+
font-weight: 500;
168+
margin-bottom: $spacer;
169+
}
170+
149171
.settings-block-title {
150172
margin: 0;
151173
padding-bottom: $spacer;
@@ -160,6 +182,16 @@
160182
display: block;
161183
}
162184
}
185+
input[type="text"] {
186+
margin-bottom: 10px;
187+
width: 100%;
188+
border: 1px solid $gray-light;
189+
padding-left: 15px;
190+
height: 38px;
191+
font-size: 14px;
192+
border-radius: 10px;
193+
-webkit-box-sizing: border-box;
194+
}
163195
}
164196
}
165197
}

0 commit comments

Comments
 (0)