create-heresay 0.2.19 → 0.2.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/release/VERSION +1 -1
- package/release/functions/lib/core/version.js +1 -1
- package/release/public/demo.html +1 -1
- package/release/public/docs.html +4 -2
- package/release/public/guides/changes.json +9 -0
- package/release/public/guides/customize-apple.md +28 -0
- package/release/public/guides/customize-web.md +12 -0
- package/release/public/sdk.js +175 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-heresay",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.21",
|
|
4
4
|
"description": "Set up your own Heresay: in-app feedback that every report gets a hearing. Creates a Firebase project in your Google account and deploys the dashboard, API and SDK to it.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/release/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.2.
|
|
1
|
+
0.2.21
|
package/release/public/demo.html
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
s.dataset.version = '0.0.1-demo';
|
|
26
26
|
// The design options, so a look can be tried here before it goes in the app's code.
|
|
27
27
|
['accent', 'position', 'offset', 'button', 'label', 'style', 'size', 'fill', 'shadow', 'mark', 'theme',
|
|
28
|
-
'font', 'lang', 'placeholder', 'types', 'thanks', 'panel', 'width', 'backdrop', 'preferences', 'intro', 'trail']
|
|
28
|
+
'font', 'lang', 'placeholder', 'types', 'thanks', 'panel', 'width', 'backdrop', 'preferences', 'intro', 'trail', 'nudge']
|
|
29
29
|
.forEach(function (k) { if (q.get(k) != null) s.setAttribute('data-' + k, q.get(k)); });
|
|
30
30
|
if (q.has('preview')) s.setAttribute('data-preview', '');
|
|
31
31
|
document.body.appendChild(s);
|
package/release/public/docs.html
CHANGED
|
@@ -101,7 +101,8 @@
|
|
|
101
101
|
<tr><td><code>data-backdrop</code></td><td><code>dim</code> · <code>clear</code> · <code>blur</code></td></tr>
|
|
102
102
|
<tr><td><code>data-preferences</code></td><td><code>show</code> · <code>hide</code></td></tr>
|
|
103
103
|
<tr><td><code>data-trail</code></td><td>on · <code>off</code> · the parts to keep, like <code>pages errors requests</code>. What happened before a report: pages, clicks, failed requests, errors. The reporter sees it and can take it off. Never what anyone typed.</td></tr>
|
|
104
|
-
<tr><td><code>data-heresay-private</code></td><td>on any element of your app: clicks on it are recorded without its text</td></tr
|
|
104
|
+
<tr><td><code>data-heresay-private</code></td><td>on any element of your app: clicks on it are recorded without its text</td></tr>
|
|
105
|
+
<tr><td><code>data-nudge</code></td><td>off · <code>on</code> · the signals to watch, like <code>clicks errors</code>. When someone seems stuck (a button pressed again and again with nothing happening, an error right after a click, requests failing), a small note by the button offers to report it. Watched on the device, never sent. Once per tab; quiet for 7 days after “Not now”.</td></tr></table>
|
|
105
106
|
<p>Always there, whatever you choose: the Heresay mark on the button, the <b>Your reports</b> tab (people read why a report was declined), and <b>Powered by Heresay</b> in the panel and the introduction, so people can tell your app uses an outside tool. The widget lives in a shadow root, so your CSS can't restyle it.</p>
|
|
106
107
|
|
|
107
108
|
<h2 id="api">JavaScript API</h2>
|
|
@@ -113,6 +114,7 @@
|
|
|
113
114
|
<tr><td><code>Heresay.open({ type, text })</code></td><td>Open the report form from your own button or menu item. <code>type</code> and <code>text</code> are optional and fill it in, for example from an error screen; the person still reviews and sends it.</td></tr>
|
|
114
115
|
<tr><td><code>Heresay.on("sent", fn)</code></td><td>Calls <code>fn({ id, type })</code> after each report is sent, to thank people or count it in your analytics. Returns a function that stops it.</td></tr>
|
|
115
116
|
<tr><td><code>Heresay.introduce({ title, body })</code></td><td>Once per device, a small bubble over the button says what it's for, so people know it exists. Call it when your main screen is up (after sign-in or onboarding), or add <code>data-intro="auto"</code> to the tag. Later calls do nothing. <code>title</code> and <code>body</code> are optional, to use your own words.</td></tr>
|
|
117
|
+
<tr><td><code>Heresay.nudge()</code></td><td>Your app saw trouble itself, such as an error screen or a retry that failed: a small note by the button offers to report it. Works without <code>data-nudge</code>; the same limits apply. Returns whether it showed.</td></tr>
|
|
116
118
|
<tr><td><code>Heresay.openPreferences()</code></td><td>Open the Preferences tab: a note about their setup, sent with every report. People who aren't signed in can also add a name and an email for replies. It's all optional and saved on their device. Where the button sits is yours to choose, with <code>data-position</code>.</td></tr>
|
|
117
119
|
<tr><td><code>Heresay.close()</code></td><td>Close the panel.</td></tr></table>
|
|
118
120
|
<p>Each report also carries the page it came from: its title, its address without the query string, and the window size.</p>
|
|
@@ -185,7 +187,7 @@ connect-src ORIGIN;</code></pre>
|
|
|
185
187
|
WindowGroup { ContentView().heresayReportButton() } <span class="k">// iOS: a Report button in the corner</span>
|
|
186
188
|
}
|
|
187
189
|
}</code></pre>
|
|
188
|
-
<p>On macOS, use <code>ContentView().heresay()</code> and add <code>.commands { HeresayCommands() }</code> for <b>Help › Report a Problem…</b> (⌥⌘R). The same calls as the web SDK exist: <code>Heresay.identify(id:label:email:)</code>, <code>Heresay.presentPreferences()</code>, <code>Heresay.introduce()</code> (once per install, a welcome sheet on iOS or a small window on macOS saying where to find it; call it when the main screen appears), <code>Heresay.setScreen(_:)</code>, <code>Heresay.present(type:text:)</code>, <code>Heresay.onSent</code>, and <code>Heresay.send(_:text:)</code> for your own UI. How it looks is one <code>HeresayStyle</code> passed to <code>configure(…, style:)</code>, with the same choices as the web (corner, offset, text, pill or icon, size, fill, shadow, screens to hide it on, theme, typeface, English, French, Tamil or Hindi, report types, a thank-you line, sheet size, the Preferences tab). The defaults are recommended; the dashboard's <b>Design</b> page shows each choice and gives the Swift. The app version comes from the bundle. Native apps have no web origin to lock the key to; the rate limits still apply.</p>
|
|
190
|
+
<p>On macOS, use <code>ContentView().heresay()</code> and add <code>.commands { HeresayCommands() }</code> for <b>Help › Report a Problem…</b> (⌥⌘R). The same calls as the web SDK exist: <code>Heresay.identify(id:label:email:)</code>, <code>Heresay.presentPreferences()</code>, <code>Heresay.introduce()</code> (once per install, a welcome sheet on iOS or a small window on macOS saying where to find it; call it when the main screen appears), <code>Heresay.setScreen(_:)</code>, <code>Heresay.present(type:text:)</code>, <code>Heresay.onSent</code>, and <code>Heresay.send(_:text:)</code> for your own UI. How it looks is one <code>HeresayStyle</code> passed to <code>configure(…, style:)</code>, with the same choices as the web (corner, offset, text, pill or icon, size, fill, shadow, screens to hide it on, theme, typeface, English, French, Tamil or Hindi, report types, a thank-you line, sheet size, the Preferences tab). The defaults are recommended; the dashboard's <b>Design</b> page shows each choice and gives the Swift. The app version comes from the bundle. Reports carry what happened before them, as on the web: the screens named with <code>.heresayScreen(_:)</code> or <code>setScreen</code>, the app's own <code>Logger</code> errors, the last crash, and on macOS clicks (by accessibility label) and menu commands. The reporter sees it and can take it off; <code>configure(…, trail: [])</code> turns it off. Native apps have no web origin to lock the key to; the rate limits still apply.</p>
|
|
189
191
|
|
|
190
192
|
<h2 id="rest">Other platforms</h2>
|
|
191
193
|
<p>Android, React Native and Flutter SDKs are on the way. Until then, any app can talk to the same API. Both calls take a JSON body.</p>
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"about": "Features added to Heresay since apps were first installed. An agent in a connected repo checks these with whats_new, tells the person what's new, and asks before adding any. `detect` is what the code contains once a feature is in; `platforms` limits it to those apps; `sign_in` limits it to apps that answered that.",
|
|
3
3
|
"changes": [
|
|
4
|
+
{
|
|
5
|
+
"id": "nudge",
|
|
6
|
+
"since": "0.2.21",
|
|
7
|
+
"title": "Offer help when someone seems stuck",
|
|
8
|
+
"summary": "A small note by the Report button asks “Something not working?” when someone presses a button again and again with nothing happening, hits an error right after a click, or sees requests fail (web), clicks a disabled control again and again (macOS), or comes back after a crash (iOS and macOS). It opens the form as Broken, with what happened attached. Watched on the device, never sent; once per visit, and quiet for a week after “Not now”. Off until the app turns it on.",
|
|
9
|
+
"platforms": ["web", "ios", "macos"],
|
|
10
|
+
"detect": ["data-nudge", "nudge:", "nudge()"],
|
|
11
|
+
"how": { "web": "guide customize-web, Offering help", "ios": "guide customize-apple, Offering help", "macos": "guide customize-apple, Offering help" }
|
|
12
|
+
},
|
|
4
13
|
{
|
|
5
14
|
"id": "design-apple",
|
|
6
15
|
"since": "0.2.11",
|
|
@@ -58,9 +58,37 @@ change. The first value is the default.
|
|
|
58
58
|
|
|
59
59
|
`Heresay.setStyle(_:)` changes it later, for example when the app's own theme setting changes.
|
|
60
60
|
|
|
61
|
+
**The trail**
|
|
62
|
+
|
|
63
|
+
With each report, Heresay attaches what happened in the app in the last few minutes: screens
|
|
64
|
+
(named with `Heresay.setScreen` or `.heresayScreen("Settings")`), the app's own `Logger` errors,
|
|
65
|
+
the last crash, going offline, and on macOS clicks (by their accessibility label) and menu
|
|
66
|
+
commands. The reporter sees it in the sheet and can switch it off or leave parts out. Never what
|
|
67
|
+
anyone typed. On by default; change it only when asked.
|
|
68
|
+
|
|
69
|
+
| Option | Values |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| `configure(…, trail:)` | `.all` (default) · `[]` (off) · some of `[.screens, .clicks, .errors]` |
|
|
72
|
+
| `.heresayPrivate()` | on a view whose controls are named after someone's data: clicks inside it are recorded as "button", without the label |
|
|
73
|
+
|
|
74
|
+
**Offering help**
|
|
75
|
+
|
|
76
|
+
When someone seems stuck, a small note by the button (or in its corner on macOS) asks "Something
|
|
77
|
+
not working?" and opens the sheet as Broken, with the trail. Watched on the device, never sent. At
|
|
78
|
+
most once per launch, and not for 7 days after "Not now". Off by default: it appears on the app's
|
|
79
|
+
own screen, so add it only when asked.
|
|
80
|
+
|
|
81
|
+
| Option | Values |
|
|
82
|
+
| --- | --- |
|
|
83
|
+
| `configure(…, nudge:)` | `[]` (default, off) · `.all` · `.clicks` (macOS: a disabled control clicked 3 times in 10 s, or one spot clicked 5 times in 2 s; leave it out for games and drawing apps) · `.crash` (the app crashed last time; once, at the next launch) |
|
|
84
|
+
|
|
85
|
+
Screens make the trail readable: if the app has several screens and doesn't name them yet, add
|
|
86
|
+
`.heresayScreen("<name>")` to each screen's root view.
|
|
87
|
+
|
|
61
88
|
**Calls**
|
|
62
89
|
|
|
63
90
|
- `Heresay.present(type:text:)`: opens the sheet, filled in. The person still reviews and sends it.
|
|
91
|
+
- `Heresay.nudge()`: the app saw trouble itself (an error screen, a retry that failed): offer to report it. Works without `nudge:`; the same limits apply.
|
|
64
92
|
- `Heresay.onSent { event in ... }`: after each report is sent, with `event.id` and `event.type`, never the text.
|
|
65
93
|
- `Heresay.introduce(title:message:)`: the one-time introduction in your own words. Leave the
|
|
66
94
|
words out unless asked; the default says where to find it.
|
|
@@ -82,9 +82,21 @@ anyone typed, request bodies, headers or query strings. On by default; change it
|
|
|
82
82
|
| `data-trail` | on (default) · `off` · the parts to keep, e.g. `pages errors requests` (from `pages`, `clicks`, `requests`, `errors`) |
|
|
83
83
|
| `data-heresay-private` | on any element of the app: clicks on it are recorded as "button", without its text |
|
|
84
84
|
|
|
85
|
+
**Offering help**
|
|
86
|
+
|
|
87
|
+
When someone seems stuck, a small note by the button asks "Something not working?" and opens the
|
|
88
|
+
form as Broken, with the trail. Watched on the device, never sent. At most once per tab, and not
|
|
89
|
+
for 7 days after "Not now". Off by default: it appears on the app's own page, so add it only when
|
|
90
|
+
asked.
|
|
91
|
+
|
|
92
|
+
| Attribute | Values |
|
|
93
|
+
| --- | --- |
|
|
94
|
+
| `data-nudge` | off (default) · `on` · the signals to watch, e.g. `clicks errors` (from `clicks`: the same button or link pressed 3 times in 10 s with no change to the page; `errors`: an uncaught error within 5 s of a click; `requests`: 2 requests failing with 5xx or no answer within 30 s) |
|
|
95
|
+
|
|
85
96
|
**Calls**
|
|
86
97
|
|
|
87
98
|
- `window.Heresay?.open({ type, text })`: opens the form, filled in. The person still reviews and sends it.
|
|
99
|
+
- `window.Heresay?.nudge()`: the app saw trouble itself (an error screen, a retry that failed): offer to report it. Works without `data-nudge`; the same limits apply.
|
|
88
100
|
- `window.Heresay?.on('sent', ({ id, type }) => ...)`: after each report is sent, for example to thank them or count it in the app's analytics. It returns a function that stops listening. It never gets the report text.
|
|
89
101
|
|
|
90
102
|
## Can't be changed
|
package/release/public/sdk.js
CHANGED
|
@@ -32,6 +32,10 @@
|
|
|
32
32
|
* (pages, clicks, requests, errors). What happened in the app before
|
|
33
33
|
* a report; see "the trail" below. data-heresay-private on any element
|
|
34
34
|
* keeps its text out of click records.
|
|
35
|
+
* Offering help: data-nudge off (default) | on | the signals to watch, e.g. "clicks errors"
|
|
36
|
+
* (clicks, errors, requests). When someone seems stuck, a small note
|
|
37
|
+
* by the button asks if they want to tell the team. See "offering
|
|
38
|
+
* help" below.
|
|
35
39
|
* Optional calls, any time after the script runs:
|
|
36
40
|
* Feedback.identify({ id, label, email }) who is signed in; then nobody is asked their name
|
|
37
41
|
* Feedback.setVersion("1.4.0")
|
|
@@ -39,6 +43,7 @@
|
|
|
39
43
|
* Feedback.open({ type, text }) type and text optional: starts a report already filled in
|
|
40
44
|
* Feedback.on("sent", fn) fn({ id, type }) after each report is sent; returns an off()
|
|
41
45
|
* Feedback.introduce({ title, body }) once per device: a bubble saying the button is there
|
|
46
|
+
* Feedback.nudge() the app saw trouble itself: offer to report it, as data-nudge does
|
|
42
47
|
* data-preview for the dashboard's designer: nothing is sent or stored
|
|
43
48
|
* Feedback.openPreferences() a note about their setup, and a name and email if not signed in
|
|
44
49
|
*
|
|
@@ -111,6 +116,7 @@
|
|
|
111
116
|
trailHint: 'Recent pages, clicks and errors in this app. Never what you typed.',
|
|
112
117
|
seeTrail: 'See it',
|
|
113
118
|
trail: { page: ['page', 'pages'], click: ['click', 'clicks'], request: ['failed request', 'failed requests'], error: ['error', 'errors'], warn: ['warning', 'warnings'], state: ['connection change', 'connection changes'] },
|
|
119
|
+
nudgeAria: 'Offer to report a problem', nudgeTitle: 'Something not working?', nudgeBody: 'Tell the team what happened. A real person reads it.', nudgeYes: 'Tell the team', nudgeNo: 'Not now',
|
|
114
120
|
sentTo: 'Sent to this app’s team', powered: 'Powered by Heresay',
|
|
115
121
|
},
|
|
116
122
|
fr: {
|
|
@@ -148,6 +154,7 @@
|
|
|
148
154
|
trailHint: 'Pages, clics et erreurs récents dans cette app. Jamais ce que vous avez saisi.',
|
|
149
155
|
seeTrail: 'Voir',
|
|
150
156
|
trail: { page: ['page', 'pages'], click: ['clic', 'clics'], request: ['requête échouée', 'requêtes échouées'], error: ['erreur', 'erreurs'], warn: ['avertissement', 'avertissements'], state: ['changement de connexion', 'changements de connexion'] },
|
|
157
|
+
nudgeAria: 'Proposition de signaler un problème', nudgeTitle: 'Quelque chose ne marche pas ?', nudgeBody: 'Dites à l’équipe ce qui s’est passé. Une vraie personne le lit.', nudgeYes: 'Signaler', nudgeNo: 'Pas maintenant',
|
|
151
158
|
sentTo: 'Envoyé à l’équipe de cette app', powered: 'Propulsé par Heresay',
|
|
152
159
|
},
|
|
153
160
|
ta: {
|
|
@@ -185,6 +192,7 @@
|
|
|
185
192
|
trailHint: 'இந்த ஆப்பில் சமீபத்திய பக்கங்கள், கிளிக்குகள், பிழைகள். நீங்கள் தட்டச்சு செய்தது ஒருபோதும் இல்லை.',
|
|
186
193
|
seeTrail: 'பார்',
|
|
187
194
|
trail: { page: ['பக்கம்', 'பக்கங்கள்'], click: ['கிளிக்', 'கிளிக்குகள்'], request: ['தோல்வியடைந்த கோரிக்கை', 'தோல்வியடைந்த கோரிக்கைகள்'], error: ['பிழை', 'பிழைகள்'], warn: ['எச்சரிக்கை', 'எச்சரிக்கைகள்'], state: ['இணைப்பு மாற்றம்', 'இணைப்பு மாற்றங்கள்'] },
|
|
195
|
+
nudgeAria: 'சிக்கலைத் தெரிவிக்க ஒரு அழைப்பு', nudgeTitle: 'ஏதாவது வேலை செய்யவில்லையா?', nudgeBody: 'என்ன நடந்தது என்று குழுவிடம் சொல்லுங்கள். ஒருவர் அதைப் படிப்பார்.', nudgeYes: 'குழுவிடம் சொல்', nudgeNo: 'இப்போது வேண்டாம்',
|
|
188
196
|
sentTo: 'இந்த ஆப்பின் குழுவுக்கு அனுப்பப்படும்', powered: 'Heresay மூலம் இயங்குகிறது',
|
|
189
197
|
},
|
|
190
198
|
hi: {
|
|
@@ -222,6 +230,7 @@
|
|
|
222
230
|
trailHint: 'इस ऐप में हाल के पेज, क्लिक और त्रुटियाँ। आपने जो टाइप किया, वह कभी नहीं।',
|
|
223
231
|
seeTrail: 'देखें',
|
|
224
232
|
trail: { page: ['पेज', 'पेज'], click: ['क्लिक', 'क्लिक'], request: ['विफल अनुरोध', 'विफल अनुरोध'], error: ['त्रुटि', 'त्रुटियाँ'], warn: ['चेतावनी', 'चेतावनियाँ'], state: ['कनेक्शन बदलाव', 'कनेक्शन बदलाव'] },
|
|
233
|
+
nudgeAria: 'समस्या बताने का सुझाव', nudgeTitle: 'कुछ काम नहीं कर रहा?', nudgeBody: 'टीम को बताइए क्या हुआ। इसे कोई इंसान पढ़ता है।', nudgeYes: 'टीम को बताएँ', nudgeNo: 'अभी नहीं',
|
|
225
234
|
sentTo: 'इस ऐप की टीम को भेजा जाता है', powered: 'Heresay द्वारा संचालित',
|
|
226
235
|
},
|
|
227
236
|
};
|
|
@@ -426,6 +435,16 @@
|
|
|
426
435
|
return on;
|
|
427
436
|
})();
|
|
428
437
|
var TRAIL_MAX = 30, TRAIL_AGE = 5 * 60000;
|
|
438
|
+
// data-nudge, read here because the request watchers below serve both. See "offering help".
|
|
439
|
+
var NUDGE_SIGNALS = ['clicks', 'errors', 'requests'];
|
|
440
|
+
var NUDGE = (function () {
|
|
441
|
+
var v = attr('nudge').toLowerCase(), on = {};
|
|
442
|
+
if (PREVIEW || !v || /^(off|none|false|no)$/.test(v)) return on;
|
|
443
|
+
(v === 'on' ? NUDGE_SIGNALS : v.split(/[\s,]+/)).forEach(function (w) {
|
|
444
|
+
if (NUDGE_SIGNALS.indexOf(w) >= 0) on[w] = true;
|
|
445
|
+
});
|
|
446
|
+
return on;
|
|
447
|
+
})();
|
|
429
448
|
var trail = [];
|
|
430
449
|
|
|
431
450
|
/** The same blanking the server does (trail.ts), so it never leaves the device in the first place. */
|
|
@@ -546,7 +565,7 @@
|
|
|
546
565
|
}
|
|
547
566
|
|
|
548
567
|
// Requests: only the ones that failed, by method, path and status.
|
|
549
|
-
if (TRAIL.request && window.fetch) {
|
|
568
|
+
if ((TRAIL.request || NUDGE.requests) && window.fetch) {
|
|
550
569
|
var ofetch = window.fetch;
|
|
551
570
|
window.fetch = function (input, init) {
|
|
552
571
|
var p = ofetch.apply(window, arguments);
|
|
@@ -555,16 +574,18 @@
|
|
|
555
574
|
if (url && !ours(url)) {
|
|
556
575
|
var method = String(init && init.method || input && input.method || 'GET').toUpperCase();
|
|
557
576
|
p.then(function (res) {
|
|
558
|
-
if (!res.ok && res.type !== 'opaque') note('request', method + ' ' + shortUrl(url) + ' → ' + res.status);
|
|
577
|
+
if (!res.ok && res.type !== 'opaque') { note('request', method + ' ' + shortUrl(url) + ' → ' + res.status); requestFailed(res.status); }
|
|
559
578
|
}, function (err) {
|
|
560
|
-
if (
|
|
579
|
+
if (err && err.name === 'AbortError') return;
|
|
580
|
+
note('request', method + ' ' + shortUrl(url) + ' → failed (' + (navigator.onLine === false ? 'offline' : 'network error') + ')');
|
|
581
|
+
requestFailed(0);
|
|
561
582
|
});
|
|
562
583
|
}
|
|
563
584
|
} catch (e) { /* ignore */ }
|
|
564
585
|
return p;
|
|
565
586
|
};
|
|
566
587
|
}
|
|
567
|
-
if (TRAIL.request && window.XMLHttpRequest) {
|
|
588
|
+
if ((TRAIL.request || NUDGE.requests) && window.XMLHttpRequest) {
|
|
568
589
|
var XP = XMLHttpRequest.prototype, xopen = XP.open, xsend = XP.send;
|
|
569
590
|
XP.open = function (m, u) {
|
|
570
591
|
try { this.__heresay = { m: String(m || 'GET').toUpperCase(), u: String(u) }; } catch (e) { /* ignore */ }
|
|
@@ -577,8 +598,8 @@
|
|
|
577
598
|
var aborted = false;
|
|
578
599
|
x.addEventListener('abort', function () { aborted = true; });
|
|
579
600
|
x.addEventListener('loadend', function () {
|
|
580
|
-
if (x.status >= 400) note('request', r.m + ' ' + shortUrl(r.u) + ' → ' + x.status);
|
|
581
|
-
else if (x.status === 0 && !aborted) note('request', r.m + ' ' + shortUrl(r.u) + ' → failed (network error)');
|
|
601
|
+
if (x.status >= 400) { note('request', r.m + ' ' + shortUrl(r.u) + ' → ' + x.status); requestFailed(x.status); }
|
|
602
|
+
else if (x.status === 0 && !aborted) { note('request', r.m + ' ' + shortUrl(r.u) + ' → failed (network error)'); requestFailed(0); }
|
|
582
603
|
});
|
|
583
604
|
}
|
|
584
605
|
} catch (e) { /* ignore */ }
|
|
@@ -623,6 +644,93 @@
|
|
|
623
644
|
window.addEventListener('online', function () { note('state', 'Back online'); });
|
|
624
645
|
}
|
|
625
646
|
|
|
647
|
+
// ---- offering help ---------------------------------------------------------------------
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* data-nudge: when someone seems stuck, a small note by the button asks whether they want to
|
|
651
|
+
* tell the team. Off unless the host turns it on: it is the host's page it appears on. Watched
|
|
652
|
+
* here on the device and never sent anywhere; it only offers the form, with the trail.
|
|
653
|
+
*
|
|
654
|
+
* clicks the same button or link pressed 3 times in 10 s, and the page did not change
|
|
655
|
+
* errors an uncaught error or failed promise within 5 s of a click
|
|
656
|
+
* requests 2 requests failing (5xx or no answer) within 30 s, while online
|
|
657
|
+
*
|
|
658
|
+
* At most once per tab, and not for 7 days after "Not now".
|
|
659
|
+
*/
|
|
660
|
+
var DEAD_WAIT = 1500, DEAD_SPAN = 10000, DEAD_COUNT = 3;
|
|
661
|
+
var lastPress = 0;
|
|
662
|
+
|
|
663
|
+
// Clicks that did nothing: no change to the page and no new address within 1.5 s. Buttons and
|
|
664
|
+
// links only; fields, checkboxes and sliders change without touching the page.
|
|
665
|
+
var PRESSABLE = 'a[href],button,input[type=button],input[type=submit],input[type=reset],[role=button],[role=link],[role=menuitem],[role=tab],summary';
|
|
666
|
+
var presses = [], pending = 0, pageWatch = null;
|
|
667
|
+
function pageChanged() {
|
|
668
|
+
var now = Date.now();
|
|
669
|
+
presses.forEach(function (p) { if (now - p.at <= DEAD_WAIT) p.changed = true; });
|
|
670
|
+
}
|
|
671
|
+
function judge(p) {
|
|
672
|
+
if (--pending === 0 && pageWatch) { pageWatch.disconnect(); pageWatch = null; }
|
|
673
|
+
if (p.changed || location.href !== p.href) return;
|
|
674
|
+
p.dead = true;
|
|
675
|
+
var cut = Date.now() - DEAD_SPAN;
|
|
676
|
+
presses = presses.filter(function (q) { return q.at >= cut; });
|
|
677
|
+
var same = presses.filter(function (q) { return q.dead && q.el === p.el; });
|
|
678
|
+
if (same.length >= DEAD_COUNT) { presses = []; trouble('clicks'); }
|
|
679
|
+
}
|
|
680
|
+
if (NUDGE.clicks || NUDGE.errors) {
|
|
681
|
+
// pointerdown, not click: a disabled button gets no click, and it is the classic one to press again.
|
|
682
|
+
document.addEventListener('pointerdown', function (e) {
|
|
683
|
+
if (!e.isPrimary || e.button > 0 || !host || host.contains(e.target) || e.target === host) return;
|
|
684
|
+
lastPress = Date.now();
|
|
685
|
+
if (!NUDGE.clicks || !e.target.closest) return;
|
|
686
|
+
var c = e.target.closest(PRESSABLE);
|
|
687
|
+
if (!c || c.closest('[data-feedback-sdk]')) return;
|
|
688
|
+
// A new tab, a download, an email: the page stays as it was, and that is fine.
|
|
689
|
+
if (c.tagName === 'A' && (/^(mailto|tel|sms):/i.test(c.getAttribute('href')) || c.hasAttribute('download')
|
|
690
|
+
|| (c.target && c.target !== '_self'))) return;
|
|
691
|
+
var p = { el: c, at: lastPress, href: location.href, changed: false, dead: false };
|
|
692
|
+
presses.push(p);
|
|
693
|
+
if (!pageWatch && window.MutationObserver) {
|
|
694
|
+
pageWatch = new MutationObserver(pageChanged);
|
|
695
|
+
pageWatch.observe(document.documentElement, { childList: true, subtree: true, attributes: true, characterData: true });
|
|
696
|
+
}
|
|
697
|
+
pending++;
|
|
698
|
+
setTimeout(function () { judge(p); }, DEAD_WAIT);
|
|
699
|
+
}, true);
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
// Errors right after a click. Not from browser extensions, not the browser's ResizeObserver
|
|
703
|
+
// notice, not cross-origin "Script error." with nothing to go on.
|
|
704
|
+
function appError(msg, where) {
|
|
705
|
+
if (!lastPress || Date.now() - lastPress > 5000) return false;
|
|
706
|
+
if (/ResizeObserver loop/.test(msg || '')) return false;
|
|
707
|
+
if (/^(chrome|moz|safari(-web)?)-extension:/.test(where || '')) return false;
|
|
708
|
+
if (where && script.src && where.indexOf(script.src.split(/[?#]/)[0]) === 0) return false;
|
|
709
|
+
return true;
|
|
710
|
+
}
|
|
711
|
+
if (NUDGE.errors) {
|
|
712
|
+
window.addEventListener('error', function (e) {
|
|
713
|
+
if (e.target && e.target !== window) return; // a file that did not load
|
|
714
|
+
if (!e.filename && !e.error) return;
|
|
715
|
+
if (appError(e.message, e.filename)) trouble('errors');
|
|
716
|
+
}, true);
|
|
717
|
+
window.addEventListener('unhandledrejection', function (e) {
|
|
718
|
+
var r = e.reason, stack = r && r.stack ? String(r.stack) : '';
|
|
719
|
+
if (/(chrome|moz|safari(-web)?)-extension:/.test(stack)) return;
|
|
720
|
+
if (appError(r && r.message, '')) trouble('errors');
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// Requests failing in a row: the server, or the way to it. A 4xx is usually the app answering.
|
|
725
|
+
var fails = [];
|
|
726
|
+
function requestFailed(status) {
|
|
727
|
+
if (!NUDGE.requests || navigator.onLine === false || (status && status < 500)) return;
|
|
728
|
+
var now = Date.now();
|
|
729
|
+
fails = fails.filter(function (t) { return now - t < 30000; }).concat(now);
|
|
730
|
+
if (fails.length >= 2) { fails = []; trouble('requests'); }
|
|
731
|
+
}
|
|
732
|
+
function trouble(why) { if (NUDGE[why]) offerHelp(); }
|
|
733
|
+
|
|
626
734
|
// ---- network ---------------------------------------------------------------------------
|
|
627
735
|
|
|
628
736
|
// A 404 means the key is unknown: the app was deleted from the dashboard, or the key is
|
|
@@ -719,6 +827,8 @@
|
|
|
719
827
|
'.intro .by{margin-top:12px;padding-top:8px}',
|
|
720
828
|
'@keyframes fb-in{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}',
|
|
721
829
|
'@media (prefers-reduced-motion:reduce){.intro{animation:none}}',
|
|
830
|
+
// offering help: the introduction's bubble; with no button to point at, it sits in its place
|
|
831
|
+
'.intro.free:after{display:none}.intro.free.b{bottom:var(--fb-y)}.intro.free.t{top:var(--fb-y)}',
|
|
722
832
|
'.mark{display:inline-flex;color:var(--fb-mark)}.mark svg{display:block}.eye{fill:var(--fb-eye)}',
|
|
723
833
|
'.dot{width:8px;height:8px;border-radius:50%;background:var(--fb-acc)}',
|
|
724
834
|
|
|
@@ -889,6 +999,7 @@
|
|
|
889
999
|
var off = !revealed || hiddenHere();
|
|
890
1000
|
if (off) fab.setAttribute('hidden', ''); else fab.removeAttribute('hidden');
|
|
891
1001
|
if (off && bubble) { bubble.remove(); bubble = null; }
|
|
1002
|
+
if (off && nudgeEl) { nudgeEl.remove(); nudgeEl = null; }
|
|
892
1003
|
}
|
|
893
1004
|
/** Can the reporter see the button right now? The introduction points at it. */
|
|
894
1005
|
function fabShowing() {
|
|
@@ -910,6 +1021,7 @@
|
|
|
910
1021
|
if (dead) return;
|
|
911
1022
|
if (scrim) { if (which) { view = which; renderPanel(); } return; }
|
|
912
1023
|
if (bubble) { bubble.remove(); bubble = null; }
|
|
1024
|
+
if (nudgeEl) { nudgeEl.remove(); nudgeEl = null; }
|
|
913
1025
|
lastFocus = document.activeElement;
|
|
914
1026
|
view = which || (unseen() ? 'mine' : 'new');
|
|
915
1027
|
var cls = PANEL === 'center' ? 'center' : PLACE + (PANEL === 'sheet' ? ' sheet' : '');
|
|
@@ -1172,6 +1284,60 @@
|
|
|
1172
1284
|
return true;
|
|
1173
1285
|
}
|
|
1174
1286
|
|
|
1287
|
+
// ---- offering help: the note -----------------------------------------------------------
|
|
1288
|
+
|
|
1289
|
+
// Someone seems stuck (data-nudge), or the app says so (nudge()). A note by the button, which
|
|
1290
|
+
// takes no focus and goes by itself after 15 s unless it is being read. "Tell the team" opens
|
|
1291
|
+
// the form as Broken, with the trail. At most once per tab; "Not now" quiets it for 7 days.
|
|
1292
|
+
var NUDGE_NO = 'fbsdk.nudge.no.' + KEY, NUDGE_TAB = 'fbsdk.nudged.' + KEY, NUDGE_REST = 7 * 864e5;
|
|
1293
|
+
var nudgeEl = null;
|
|
1294
|
+
/** True if this tab was already offered help; otherwise marks it. */
|
|
1295
|
+
function offeredInTab() {
|
|
1296
|
+
try {
|
|
1297
|
+
if (PREVIEW) throw 0;
|
|
1298
|
+
if (sessionStorage.getItem(NUDGE_TAB)) return true;
|
|
1299
|
+
sessionStorage.setItem(NUDGE_TAB, '1');
|
|
1300
|
+
} catch (e) {
|
|
1301
|
+
if (mem[NUDGE_TAB]) return true;
|
|
1302
|
+
mem[NUDGE_TAB] = '1';
|
|
1303
|
+
}
|
|
1304
|
+
return false;
|
|
1305
|
+
}
|
|
1306
|
+
function offerHelp() {
|
|
1307
|
+
if (dead || scrim || bubble || nudgeEl || !host.isConnected || hiddenHere() || document.visibilityState === 'hidden') return false;
|
|
1308
|
+
if (Date.now() - (+load(NUDGE_NO) || 0) < NUDGE_REST) return false;
|
|
1309
|
+
if (offeredInTab()) return false;
|
|
1310
|
+
var timer = null;
|
|
1311
|
+
var done = function (no) {
|
|
1312
|
+
clearTimeout(timer);
|
|
1313
|
+
if (no) save(NUDGE_NO, String(Date.now()));
|
|
1314
|
+
if (nudgeEl) { nudgeEl.remove(); nudgeEl = null; }
|
|
1315
|
+
};
|
|
1316
|
+
var later = function () { clearTimeout(timer); timer = setTimeout(function () { done(false); }, 15000); };
|
|
1317
|
+
var stay = function () { clearTimeout(timer); };
|
|
1318
|
+
nudgeEl = el('div', {
|
|
1319
|
+
class: 'intro nudge ' + PLACE + ' st-' + STYLE + (fabShowing() ? '' : ' free'),
|
|
1320
|
+
role: 'status', 'aria-label': S.nudgeAria,
|
|
1321
|
+
onpointerenter: stay, onpointerleave: later, onfocusin: stay, onfocusout: later,
|
|
1322
|
+
onkeydown: function (e) { if (e.key === 'Escape') done(true); },
|
|
1323
|
+
}, [
|
|
1324
|
+
el('b', { text: S.nudgeTitle }),
|
|
1325
|
+
el('p', { text: S.nudgeBody }),
|
|
1326
|
+
el('div', { class: 'row' }, [
|
|
1327
|
+
el('button', { class: 'link', type: 'button', text: S.nudgeNo, onclick: function () { done(true); } }),
|
|
1328
|
+
el('button', { class: 'send', type: 'button', text: S.nudgeYes, onclick: function () {
|
|
1329
|
+
done(false);
|
|
1330
|
+
if (!state.type && OFFERED.some(function (t) { return t.id === 'broken'; })) state.type = 'broken';
|
|
1331
|
+
open('new');
|
|
1332
|
+
} }),
|
|
1333
|
+
]),
|
|
1334
|
+
byline(false),
|
|
1335
|
+
]);
|
|
1336
|
+
root.appendChild(nudgeEl);
|
|
1337
|
+
later();
|
|
1338
|
+
return true;
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1175
1341
|
function mount() {
|
|
1176
1342
|
if (dead) return;
|
|
1177
1343
|
if (!host.isConnected) document.body.appendChild(host);
|
|
@@ -1205,6 +1371,9 @@
|
|
|
1205
1371
|
openPreferences: function () { if (PREFS_TAB) open('prefs'); },
|
|
1206
1372
|
/** Show the one-time introduction now. False if it was already shown on this device. */
|
|
1207
1373
|
introduce: function (o) { return introduce(o); },
|
|
1374
|
+
/** The app saw trouble itself (an error screen, a retry that failed): offer to report it.
|
|
1375
|
+
* Works without data-nudge; the same limits apply. False if it did not show. */
|
|
1376
|
+
nudge: function () { return offerHelp(); },
|
|
1208
1377
|
/** on('sent', fn): fn({ id, type }) after each report is sent. Returns a function that stops it. */
|
|
1209
1378
|
on: function (event, fn) {
|
|
1210
1379
|
if (event !== 'sent' || typeof fn !== 'function') return function () {};
|