create-heresay 0.2.20 → 0.2.22

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-heresay",
3
- "version": "0.2.20",
3
+ "version": "0.2.22",
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.20
1
+ 0.2.22
@@ -52,6 +52,14 @@ export function parseContext(v) {
52
52
  framework: isFramework(c.framework) ? c.framework : null,
53
53
  page_title: f('page_title'), page_url: pageUrl(c.page_url),
54
54
  viewport: typeof c.viewport === 'string' && /^\d{1,5}x\d{1,5}$/.test(c.viewport) ? c.viewport : null,
55
+ locale: typeof c.locale === 'string' && /^[A-Za-z]{2,3}([_-][A-Za-z0-9]{2,8}){0,3}$/.test(c.locale) ? c.locale : null,
56
+ timezone: typeof c.timezone === 'string' && /^[A-Za-z0-9_+\-/]{1,64}$/.test(c.timezone) ? c.timezone : null,
57
+ theme: c.theme === 'light' || c.theme === 'dark' ? c.theme : null,
58
+ device: str(c.device, 80), network: str(c.network, 80),
59
+ screen: typeof c.screen === 'string' && /^\d{1,5}x\d{1,5}(@[\d.]{1,4}x)?$/.test(c.screen) ? c.screen : null,
60
+ session_s: typeof c.session_s === 'number' && Number.isFinite(c.session_s) && c.session_s >= 0
61
+ ? Math.min(Math.round(c.session_s), 30 * 86_400) : null,
62
+ settings: str(c.settings, 120),
55
63
  };
56
64
  }
57
65
  /** http(s) only, and the query string dropped here too: it is where apps put tokens. */
@@ -96,8 +104,13 @@ export function agentPrompt(project, t) {
96
104
  const ctx = [
97
105
  ['Screen / route', c.route], ['Page', c.page_title], ['URL', c.page_url],
98
106
  ['App version', c.app_version], ['Platform', c.platform], ['OS', c.os], ['Browser', c.browser],
99
- ['Viewport', c.viewport],
107
+ ['Device', c.device], ['Viewport', c.viewport], ['Screen', c.screen], ['Theme', c.theme],
108
+ ['Language', c.locale], ['Time zone', c.timezone], ['Network', c.network], ['Settings', c.settings],
109
+ ['In the app for', c.session_s != null ? duration(c.session_s) : null],
100
110
  ].filter(([, v]) => v).map(([k, v]) => `- ${k}: ${v}`).join('\n');
111
+ // The last thing that went wrong, so it isn't lost in a long trail.
112
+ const worst = [...(t.trail ?? [])].reverse().find((e) => e.kind === 'error')
113
+ ?? [...(t.trail ?? [])].reverse().find((e) => e.kind === 'request' || e.kind === 'warn');
101
114
  const fence = '"""';
102
115
  return [
103
116
  `A user of ${project.name} reported something and the developer accepted it. Fix it.`,
@@ -110,12 +123,21 @@ export function agentPrompt(project, t) {
110
123
  fence,
111
124
  t.text.replaceAll(fence, "''"),
112
125
  ...(t.reporter_note ? ['', `About their setup: ${t.reporter_note.replaceAll(fence, "''")}`] : []),
126
+ ...(worst ? ['', `Last thing that went wrong, ${duration(worst.ago)} before they sent it: ${worst.text.replaceAll(fence, "''")}`] : []),
113
127
  ...(t.trail?.length ? ['', 'What happened in the app before they sent it, recorded by the SDK on their device (oldest first):',
114
128
  ...trailLines(t.trail).map((l) => l.replaceAll(fence, "''"))] : []),
115
129
  fence,
116
130
  ...(t.note ? ['', `Developer's note: ${t.note}`] : []),
117
131
  ].join('\n');
118
132
  }
133
+ /** 75 → '1 min 15 s', 7300 → '2 h 1 min'. */
134
+ export function duration(s) {
135
+ if (s < 60)
136
+ return `${s} s`;
137
+ if (s < 3600)
138
+ return `${Math.floor(s / 60)} min${s % 60 ? ` ${s % 60} s` : ''}`;
139
+ return `${Math.floor(s / 3600)} h${Math.floor(s % 3600 / 60) ? ` ${Math.floor(s % 3600 / 60)} min` : ''}`;
140
+ }
119
141
  export async function handle(req, deps) {
120
142
  try {
121
143
  return await route(req, deps);
@@ -7,7 +7,7 @@
7
7
  * before reporting. So it is cleaned here whatever the SDK did, and an agent gets it fenced.
8
8
  */
9
9
  export const TRAIL_KINDS = ['page', 'click', 'request', 'error', 'warn', 'state'];
10
- export const TRAIL_LIMITS = { events: 30, textMax: 200, detailMax: 600, totalMax: 8000, agoMax: 3600, nMax: 999 };
10
+ export const TRAIL_LIMITS = { events: 50, textMax: 200, detailMax: 600, totalMax: 12000, agoMax: 3600, nMax: 999 };
11
11
  /**
12
12
  * Blanks what tends to be personal or secret, in case the SDK missed it or something other than
13
13
  * the SDK sent this. Emails, bearer tokens, JWTs, long opaque strings, long numbers, query strings.
@@ -1,3 +1,3 @@
1
1
  /** The Heresay release. Bumped by the release script; the CLI and /v1/health report it. */
2
- export const VERSION = '0.2.20';
2
+ export const VERSION = '0.2.22';
3
3
  //# sourceMappingURL=version.js.map
@@ -1374,6 +1374,14 @@
1374
1374
  .filter(Boolean).join(' · ');
1375
1375
  }
1376
1376
 
1377
+ /** The device around the app: what layout, language and timing bugs depend on. */
1378
+ function deviceLine(c) {
1379
+ var s = c.session_s;
1380
+ var inApp = s == null ? null : 'in the app ' + (s < 60 ? s + ' s' : s < 3600 ? Math.floor(s / 60) + ' min' : Math.floor(s / 3600) + ' h ' + Math.floor(s % 3600 / 60) + ' min');
1381
+ return [c.device, c.screen, c.theme && c.theme + ' mode', c.locale, c.timezone, c.network, c.settings, inApp]
1382
+ .filter(Boolean).join(' · ');
1383
+ }
1384
+
1377
1385
  var TRAIL_LABEL = { page: 'Page', click: 'Click', request: 'Request', error: 'Error', warn: 'Warning', state: 'Device' };
1378
1386
 
1379
1387
  /**
@@ -1548,6 +1556,7 @@
1548
1556
  ]),
1549
1557
  el('p', { class: 'text', text: r.text }),
1550
1558
  el('div', { class: 'ctx', text: ctxLine(r.context) }),
1559
+ deviceLine(r.context) ? el('div', { class: 'ctx', text: deviceLine(r.context) }) : null,
1551
1560
  r.context.page_url ? el('div', { class: 'ctx' }, [el('a', { href: r.context.page_url, target: '_blank', rel: 'noopener noreferrer', text: r.context.page_url })]) : null,
1552
1561
  reporterLine(r.context, r.reporter),
1553
1562
  trailView(r.trail),
@@ -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);
@@ -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></table>
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>
@@ -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",
@@ -71,12 +71,24 @@ anyone typed. On by default; change it only when asked.
71
71
  | `configure(…, trail:)` | `.all` (default) · `[]` (off) · some of `[.screens, .clicks, .errors]` |
72
72
  | `.heresayPrivate()` | on a view whose controls are named after someone's data: clicks inside it are recorded as "button", without the label |
73
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
+
74
85
  Screens make the trail readable: if the app has several screens and doesn't name them yet, add
75
86
  `.heresayScreen("<name>")` to each screen's root view.
76
87
 
77
88
  **Calls**
78
89
 
79
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.
80
92
  - `Heresay.onSent { event in ... }`: after each report is sent, with `event.id` and `event.type`, never the text.
81
93
  - `Heresay.introduce(title:message:)`: the one-time introduction in your own words. Leave the
82
94
  words out unless asked; the default says where to find it.
@@ -73,18 +73,35 @@ default says what matters.
73
73
  **The trail**
74
74
 
75
75
  With each report, the widget attaches what happened in the app in the last few minutes:
76
- pages visited, what was clicked (by its label), requests that failed, errors and console
77
- warnings. The reporter sees it in the form and can switch it off or leave parts out. Never what
78
- anyone typed, request bodies, headers or query strings. On by default; change it only when asked.
76
+ pages visited (with their titles), what was clicked (by its label, and the dialog, form or menu
77
+ it was in), forms sent and fields the browser refused (by label and why), requests that failed
78
+ or took 3 s or more (with how long), errors, console warnings, alerts the app showed, freezes of
79
+ a second or more, and leaving the tab and coming back. Each report also carries the device
80
+ around the app: phone or desktop, touch or mouse, screen, light or dark, language, time zone,
81
+ connection, and settings such as reduced motion. The reporter sees all of it in the form and can
82
+ switch the trail off or leave parts out. Never what anyone typed, request bodies, headers or
83
+ query strings. On by default; change it only when asked.
79
84
 
80
85
  | Attribute | Values |
81
86
  | --- | --- |
82
87
  | `data-trail` | on (default) · `off` · the parts to keep, e.g. `pages errors requests` (from `pages`, `clicks`, `requests`, `errors`) |
83
88
  | `data-heresay-private` | on any element of the app: clicks on it are recorded as "button", without its text |
84
89
 
90
+ **Offering help**
91
+
92
+ When someone seems stuck, a small note by the button asks "Something not working?" and opens the
93
+ form as Broken, with the trail. Watched on the device, never sent. At most once per tab, and not
94
+ for 7 days after "Not now". Off by default: it appears on the app's own page, so add it only when
95
+ asked.
96
+
97
+ | Attribute | Values |
98
+ | --- | --- |
99
+ | `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) |
100
+
85
101
  **Calls**
86
102
 
87
103
  - `window.Heresay?.open({ type, text })`: opens the form, filled in. The person still reviews and sends it.
104
+ - `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
105
  - `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
106
 
90
107
  ## Can't be 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
  *
@@ -84,8 +89,8 @@
84
89
  what: 'What is it?', whatHappened: 'What happened?', ph: 'What happened, or what would you change?',
85
90
  send: 'Send', sending: 'Sending…',
86
91
  pickType: 'Pick what kind of report this is.', sayWhat: 'Say what happened.', cantSend: 'Could not send. Try again.',
87
- attachedPrefs: 'This page, the app version and your preferences are attached.',
88
- attached: 'This page and the app version are attached.',
92
+ attachedPrefs: 'This page, the app version, device details and your preferences are attached.',
93
+ attached: 'This page, the app version and device details are attached.',
89
94
  types: {
90
95
  broken: ['Broken', 'Something does not work'],
91
96
  confusing: ['Confusing', 'I could not tell how to do something'],
@@ -109,8 +114,9 @@
109
114
  got: 'Got it', tryIt: 'Try it',
110
115
  attachTrail: 'Attach what happened',
111
116
  trailHint: 'Recent pages, clicks and errors in this app. Never what you typed.',
112
- seeTrail: 'See it',
113
- trail: { page: ['page', 'pages'], click: ['click', 'clicks'], request: ['failed request', 'failed requests'], error: ['error', 'errors'], warn: ['warning', 'warnings'], state: ['connection change', 'connection changes'] },
117
+ seeTrail: 'See it', alsoSent: 'Also sent: ',
118
+ trail: { page: ['page', 'pages'], click: ['click', 'clicks'], request: ['failed request', 'failed requests'], error: ['error', 'errors'], warn: ['warning', 'warnings'], state: ['device event', 'device events'] },
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: {
@@ -121,8 +127,8 @@
121
127
  what: 'De quoi s’agit-il ?', whatHappened: 'Que s’est-il passé ?', ph: 'Que s’est-il passé, ou que changeriez-vous ?',
122
128
  send: 'Envoyer', sending: 'Envoi…',
123
129
  pickType: 'Choisissez le type de signalement.', sayWhat: 'Dites ce qui s’est passé.', cantSend: 'Envoi impossible. Réessayez.',
124
- attachedPrefs: 'Cette page, la version de l’app et vos préférences sont jointes.',
125
- attached: 'Cette page et la version de l’app sont jointes.',
130
+ attachedPrefs: 'Cette page, la version de l’app, les détails de l’appareil et vos préférences sont joints.',
131
+ attached: 'Cette page, la version de l’app et les détails de l’appareil sont joints.',
126
132
  types: {
127
133
  broken: ['Cassé', 'Quelque chose ne marche pas'],
128
134
  confusing: ['Déroutant', 'Je ne voyais pas comment faire'],
@@ -146,8 +152,9 @@
146
152
  got: 'Compris', tryIt: 'Essayer',
147
153
  attachTrail: 'Joindre ce qui s’est passé',
148
154
  trailHint: 'Pages, clics et erreurs récents dans cette app. Jamais ce que vous avez saisi.',
149
- seeTrail: 'Voir',
150
- 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'] },
155
+ seeTrail: 'Voir', alsoSent: 'Aussi envoyé : ',
156
+ trail: { page: ['page', 'pages'], click: ['clic', 'clics'], request: ['requête échouée', 'requêtes échouées'], error: ['erreur', 'erreurs'], warn: ['avertissement', 'avertissements'], state: ['événement de l’appareil', 'événements de l’appareil'] },
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: {
@@ -158,8 +165,8 @@
158
165
  what: 'இது என்ன வகை?', whatHappened: 'என்ன நடந்தது?', ph: 'என்ன நடந்தது, அல்லது எதை மாற்ற விரும்புகிறீர்கள்?',
159
166
  send: 'அனுப்பு', sending: 'அனுப்புகிறது…',
160
167
  pickType: 'இது எந்த வகைப் புகார் என்பதைத் தேர்ந்தெடுக்கவும்.', sayWhat: 'என்ன நடந்தது என்று சொல்லுங்கள்.', cantSend: 'அனுப்ப முடியவில்லை. மீண்டும் முயலவும்.',
161
- attachedPrefs: 'இந்தப் பக்கம், ஆப் பதிப்பு மற்றும் உங்கள் விருப்பங்கள் இணைக்கப்படும்.',
162
- attached: 'இந்தப் பக்கமும் ஆப் பதிப்பும் இணைக்கப்படும்.',
168
+ attachedPrefs: 'இந்தப் பக்கம், ஆப் பதிப்பு, சாதன விவரங்கள் மற்றும் உங்கள் விருப்பங்கள் இணைக்கப்படும்.',
169
+ attached: 'இந்தப் பக்கம், ஆப் பதிப்பு மற்றும் சாதன விவரங்கள் இணைக்கப்படும்.',
163
170
  types: {
164
171
  broken: ['வேலை செய்யவில்லை', 'ஏதோ ஒன்று சரியாக இயங்கவில்லை'],
165
172
  confusing: ['குழப்பமாக உள்ளது', 'எப்படிச் செய்வது என்று புரியவில்லை'],
@@ -183,8 +190,9 @@
183
190
  got: 'சரி', tryIt: 'முயன்று பாருங்கள்',
184
191
  attachTrail: 'என்ன நடந்தது என்பதையும் இணை',
185
192
  trailHint: 'இந்த ஆப்பில் சமீபத்திய பக்கங்கள், கிளிக்குகள், பிழைகள். நீங்கள் தட்டச்சு செய்தது ஒருபோதும் இல்லை.',
186
- seeTrail: 'பார்',
187
- trail: { page: ['பக்கம்', 'பக்கங்கள்'], click: ['கிளிக்', 'கிளிக்குகள்'], request: ['தோல்வியடைந்த கோரிக்கை', 'தோல்வியடைந்த கோரிக்கைகள்'], error: ['பிழை', 'பிழைகள்'], warn: ['எச்சரிக்கை', 'எச்சரிக்கைகள்'], state: ['இணைப்பு மாற்றம்', 'இணைப்பு மாற்றங்கள்'] },
193
+ seeTrail: 'பார்', alsoSent: 'இவையும் அனுப்பப்படும்: ',
194
+ trail: { page: ['பக்கம்', 'பக்கங்கள்'], click: ['கிளிக்', 'கிளிக்குகள்'], request: ['தோல்வியடைந்த கோரிக்கை', 'தோல்வியடைந்த கோரிக்கைகள்'], error: ['பிழை', 'பிழைகள்'], warn: ['எச்சரிக்கை', 'எச்சரிக்கைகள்'], state: ['சாதன நிகழ்வு', 'சாதன நிகழ்வுகள்'] },
195
+ nudgeAria: 'சிக்கலைத் தெரிவிக்க ஒரு அழைப்பு', nudgeTitle: 'ஏதாவது வேலை செய்யவில்லையா?', nudgeBody: 'என்ன நடந்தது என்று குழுவிடம் சொல்லுங்கள். ஒருவர் அதைப் படிப்பார்.', nudgeYes: 'குழுவிடம் சொல்', nudgeNo: 'இப்போது வேண்டாம்',
188
196
  sentTo: 'இந்த ஆப்பின் குழுவுக்கு அனுப்பப்படும்', powered: 'Heresay மூலம் இயங்குகிறது',
189
197
  },
190
198
  hi: {
@@ -195,8 +203,8 @@
195
203
  what: 'यह क्या है?', whatHappened: 'क्या हुआ?', ph: 'क्या हुआ, या आप क्या बदलना चाहेंगे?',
196
204
  send: 'भेजें', sending: 'भेजा जा रहा है…',
197
205
  pickType: 'चुनें कि यह किस तरह की रिपोर्ट है।', sayWhat: 'बताइए क्या हुआ।', cantSend: 'भेजा नहीं जा सका। फिर से कोशिश करें।',
198
- attachedPrefs: 'यह पेज, ऐप का वर्शन और आपकी प्राथमिकताएँ साथ भेजी जाती हैं।',
199
- attached: 'यह पेज और ऐप का वर्शन साथ भेजे जाते हैं।',
206
+ attachedPrefs: 'यह पेज, ऐप का वर्शन, डिवाइस की जानकारी और आपकी प्राथमिकताएँ साथ भेजी जाती हैं।',
207
+ attached: 'यह पेज, ऐप का वर्शन और डिवाइस की जानकारी साथ भेजी जाती है।',
200
208
  types: {
201
209
  broken: ['टूटा हुआ', 'कुछ काम नहीं कर रहा'],
202
210
  confusing: ['उलझन भरा', 'समझ नहीं आया कि कैसे करें'],
@@ -220,8 +228,9 @@
220
228
  got: 'ठीक है', tryIt: 'आज़माएँ',
221
229
  attachTrail: 'क्या हुआ, वह भी भेजें',
222
230
  trailHint: 'इस ऐप में हाल के पेज, क्लिक और त्रुटियाँ। आपने जो टाइप किया, वह कभी नहीं।',
223
- seeTrail: 'देखें',
224
- trail: { page: ['पेज', 'पेज'], click: ['क्लिक', 'क्लिक'], request: ['विफल अनुरोध', 'विफल अनुरोध'], error: ['त्रुटि', 'त्रुटियाँ'], warn: ['चेतावनी', 'चेतावनियाँ'], state: ['कनेक्शन बदलाव', 'कनेक्शन बदलाव'] },
231
+ seeTrail: 'देखें', alsoSent: 'यह भी भेजा जाता है: ',
232
+ trail: { page: ['पेज', 'पेज'], click: ['क्लिक', 'क्लिक'], request: ['विफल अनुरोध', 'विफल अनुरोध'], error: ['त्रुटि', 'त्रुटियाँ'], warn: ['चेतावनी', 'चेतावनियाँ'], state: ['डिवाइस घटना', 'डिवाइस घटनाएँ'] },
233
+ nudgeAria: 'समस्या बताने का सुझाव', nudgeTitle: 'कुछ काम नहीं कर रहा?', nudgeBody: 'टीम को बताइए क्या हुआ। इसे कोई इंसान पढ़ता है।', nudgeYes: 'टीम को बताएँ', nudgeNo: 'अभी नहीं',
225
234
  sentTo: 'इस ऐप की टीम को भेजा जाता है', powered: 'Heresay द्वारा संचालित',
226
235
  },
227
236
  };
@@ -404,14 +413,44 @@
404
413
  page_title: (document.title || '').trim() || null,
405
414
  page_url: pageUrl(),
406
415
  viewport: Math.round(window.innerWidth) + 'x' + Math.round(window.innerHeight),
416
+ locale: navigator.language || null,
417
+ timezone: (function () { try { return Intl.DateTimeFormat().resolvedOptions().timeZone || null; } catch (e) { return null; } })(),
418
+ theme: media('(prefers-color-scheme: dark)') ? 'dark' : 'light',
419
+ device: deviceKind(),
420
+ network: network(),
421
+ screen: screen && screen.width ? screen.width + 'x' + screen.height + '@' + (Math.round((window.devicePixelRatio || 1) * 100) / 100) + 'x' : null,
422
+ session_s: Math.round(((window.performance && performance.now()) || 0) / 1000),
423
+ settings: [media('(prefers-reduced-motion: reduce)') && 'reduced motion', media('(prefers-contrast: more)') && 'more contrast',
424
+ media('(forced-colors: active)') && 'forced colours', zoom()].filter(Boolean).join(', ') || null,
407
425
  };
408
426
  }
409
427
 
428
+ function media(q) { try { return window.matchMedia(q).matches; } catch (e) { return false; } }
429
+ /** 'phone, touch', 'tablet, touch', 'desktop, mouse': what the layout had to work on. */
430
+ function deviceKind() {
431
+ var ua = navigator.userAgent;
432
+ var kind = /iPad|Tablet|Android(?!.*Mobi)/.test(ua) || (/Macintosh/.test(ua) && navigator.maxTouchPoints > 1) ? 'tablet'
433
+ : /Mobi|iPhone|Android/.test(ua) ? 'phone' : 'desktop';
434
+ return kind + ', ' + (media('(pointer: coarse)') ? 'touch' : 'mouse');
435
+ }
436
+ /** How the connection looked to the browser: '4g', '3g, data saver', 'offline'. Not every browser says. */
437
+ function network() {
438
+ if (navigator.onLine === false) return 'offline';
439
+ var c = navigator.connection;
440
+ if (!c || !c.effectiveType) return null;
441
+ return c.effectiveType + (c.saveData ? ', data saver' : '');
442
+ }
443
+ /** Page zoom, when the browser shows it: a zoomed page reflows like a narrow one. */
444
+ function zoom() {
445
+ var z = window.visualViewport && window.visualViewport.scale;
446
+ return z && Math.abs(z - 1) > 0.05 ? 'zoomed ' + Math.round(z * 100) + '%' : null;
447
+ }
448
+
410
449
  // ---- the trail -------------------------------------------------------------------------
411
450
 
412
451
  /**
413
452
  * What happened in the app before a report: pages, clicks, requests that failed, errors. Kept
414
- * in memory on this device only (the newest 30, for 5 minutes) and sent only with a report,
453
+ * in memory on this device only (the newest 50, for 5 minutes) and sent only with a report,
415
454
  * only if the reporter leaves "Attach what happened" on. Never what anyone typed, never request
416
455
  * or response bodies or headers, never query strings. Nothing is recorded inside the widget.
417
456
  */
@@ -425,7 +464,17 @@
425
464
  if (on.page || on.request || on.error) on.state = true;
426
465
  return on;
427
466
  })();
428
- var TRAIL_MAX = 30, TRAIL_AGE = 5 * 60000;
467
+ var TRAIL_MAX = 50, TRAIL_AGE = 5 * 60000;
468
+ // data-nudge, read here because the request watchers below serve both. See "offering help".
469
+ var NUDGE_SIGNALS = ['clicks', 'errors', 'requests'];
470
+ var NUDGE = (function () {
471
+ var v = attr('nudge').toLowerCase(), on = {};
472
+ if (PREVIEW || !v || /^(off|none|false|no)$/.test(v)) return on;
473
+ (v === 'on' ? NUDGE_SIGNALS : v.split(/[\s,]+/)).forEach(function (w) {
474
+ if (NUDGE_SIGNALS.indexOf(w) >= 0) on[w] = true;
475
+ });
476
+ return on;
477
+ })();
429
478
  var trail = [];
430
479
 
431
480
  /** The same blanking the server does (trail.ts), so it never leaves the device in the first place. */
@@ -444,17 +493,20 @@
444
493
  }
445
494
 
446
495
  var noting = false;
447
- function note(kind, text, detail) {
448
- if (!TRAIL[kind] || noting) return;
496
+ /** `part` is the data-trail part that allows it, when that isn't the kind's own. */
497
+ function note(kind, text, detail, part) {
498
+ if (!(part ? TRAIL[part] : TRAIL[kind]) || noting) return;
449
499
  noting = true;
450
500
  try {
451
501
  text = scrub(text, 200);
452
502
  if (!text) return;
453
503
  var now = Date.now(), last = trail[trail.length - 1];
454
- if (last && last.kind === kind && last.text === text) { last.n++; last.at = now; return; }
455
- trail.push({ kind: kind, at: now, text: text, detail: detail ? scrub(detail, 600) : null, n: 1 });
504
+ if (last && last.kind === kind && last.text === text) { last.n++; last.at = now; return last; }
505
+ var e = { kind: kind, at: now, text: text, detail: detail ? scrub(detail, 600) : null, n: 1 };
506
+ trail.push(e);
456
507
  if (trail.length > TRAIL_MAX) trail.shift();
457
- } catch (e) { /* never break the app over a record */ } finally { noting = false; }
508
+ return e;
509
+ } catch (x) { /* never break the app over a record */ } finally { noting = false; }
458
510
  }
459
511
  function recentTrail() {
460
512
  var cut = Date.now() - TRAIL_AGE;
@@ -499,12 +551,22 @@
499
551
 
500
552
  // Pages: any router changes the address through history, so watch that.
501
553
  var lastWhere = null;
502
- function onPage() {
554
+ function titled(w) {
555
+ var t = (document.title || '').replace(/\s+/g, ' ').trim();
556
+ return w + (t ? ' "' + (t.length > 60 ? t.slice(0, 59) + '…' : t) + '"' : '');
557
+ }
558
+ function onPage(first) {
503
559
  var w = location.pathname + location.hash;
504
- if (w !== lastWhere) { lastWhere = w; note('page', w); }
560
+ if (w === lastWhere) return;
561
+ lastWhere = w;
562
+ if (first === true) { note('page', titled(w)); return; }
563
+ // Single-page apps set the title just after the address: the entry goes in now, in order,
564
+ // and gets the title a moment later.
565
+ var e = note('page', w);
566
+ if (e) setTimeout(function () { var t = scrub(titled(w), 200); if (t) e.text = t; }, 150);
505
567
  }
506
568
  if (TRAIL.page) {
507
- onPage();
569
+ onPage(true);
508
570
  ['pushState', 'replaceState'].forEach(function (m) {
509
571
  var orig = history[m];
510
572
  if (typeof orig !== 'function') return;
@@ -520,7 +582,8 @@
520
582
 
521
583
  // Clicks: what was clicked, by its label. Never a field's value.
522
584
  var CLICKABLE = 'a,button,input,select,textarea,label,summary,[role=button],[role=link],[role=tab],[role=menuitem],[role=checkbox],[role=switch],[role=option]';
523
- function clicked(t) {
585
+ /** `bare` leaves out where it is. */
586
+ function clicked(t, bare) {
524
587
  var hit = t.closest && t.closest(CLICKABLE), n = hit || t;
525
588
  if (!n.tagName) return null;
526
589
  var tag = n.tagName.toLowerCase(), type = (n.getAttribute('type') || '').toLowerCase();
@@ -536,7 +599,24 @@
536
599
  || n.getAttribute('title') || n.getAttribute('alt') || '';
537
600
  name = name.replace(/\s+/g, ' ').trim();
538
601
  if (name.length > 40) name = name.slice(0, 39) + '…';
539
- return what + (name ? ' "' + name + '"' : '');
602
+ return what + (name ? ' "' + name + '"' : '') + (bare ? '' : where(n));
603
+ }
604
+
605
+ /** The dialog, form, menu or region a control is in, by its name: ' in dialog "Edit profile"'. */
606
+ var AREAS = 'dialog,[role=dialog],[role=alertdialog],[role=menu],[role=tabpanel],form,nav,[role=navigation],[role=search],aside,section[aria-label],section[aria-labelledby],[role=region]';
607
+ function where(n) {
608
+ var a = n.parentElement && n.parentElement.closest(AREAS);
609
+ if (!a || a.closest('[data-heresay-private]')) return '';
610
+ var tag = a.tagName.toLowerCase(), role = a.getAttribute('role');
611
+ var kind = role === 'alertdialog' ? 'dialog' : role === 'navigation' || tag === 'nav' ? 'navigation'
612
+ : role === 'tabpanel' ? 'tab' : role === 'search' ? 'search' : role || (tag === 'aside' ? 'sidebar' : tag === 'section' ? 'section' : tag);
613
+ var by = a.getAttribute('aria-labelledby');
614
+ var label = a.getAttribute('aria-label')
615
+ || (by && by.split(/\s+/).map(function (id) { var x = document.getElementById(id); return x ? x.textContent : ''; }).join(' '))
616
+ || ((a.querySelector('h1,h2,h3,legend') || {}).textContent) || '';
617
+ label = label.replace(/\s+/g, ' ').trim();
618
+ if (label.length > 30) label = label.slice(0, 29) + '…';
619
+ return ' in ' + kind + (label ? ' "' + label + '"' : '');
540
620
  }
541
621
  if (TRAIL.click) {
542
622
  document.addEventListener('click', function (e) {
@@ -545,8 +625,35 @@
545
625
  }, true);
546
626
  }
547
627
 
548
- // Requests: only the ones that failed, by method, path and status.
549
- if (TRAIL.request && window.fetch) {
628
+ // Forms: sent, and the fields the browser refused, by their label and why. Never their value.
629
+ var WHY = { valueMissing: 'is required', typeMismatch: 'is not in the right format', patternMismatch: 'does not match the format asked for',
630
+ tooShort: 'is too short', tooLong: 'is too long', rangeUnderflow: 'is too low', rangeOverflow: 'is too high',
631
+ stepMismatch: 'is not an allowed value', badInput: 'could not be read' };
632
+ if (TRAIL.click) {
633
+ document.addEventListener('submit', function (e) {
634
+ var f = e.target;
635
+ if (!f || !f.tagName || host.contains(f)) return;
636
+ var name = f.closest('[data-heresay-private]') ? '' : (f.getAttribute('aria-label') || f.getAttribute('name') || ((f.querySelector('h1,h2,h3,legend') || {}).textContent) || '');
637
+ name = name.replace(/\s+/g, ' ').trim().slice(0, 40);
638
+ note('click', 'form' + (name ? ' "' + name + '"' : '') + ' sent');
639
+ }, true);
640
+ document.addEventListener('invalid', function (e) {
641
+ var t = e.target;
642
+ if (!t || !t.validity || host.contains(t)) return;
643
+ var why = Object.keys(WHY).filter(function (k) { return t.validity[k]; })[0];
644
+ note('warn', clicked(t, true) + ' ' + (WHY[why] || 'was refused'), null, 'click');
645
+ }, true);
646
+ }
647
+
648
+ // Requests: the ones that failed, and the ones so slow someone would notice, by method, path,
649
+ // status and how long they took.
650
+ /** ' in 2.4 s', past a second; quicker than that, the time says nothing. */
651
+ function took(t0) { var ms = Date.now() - t0; return ms >= 1000 ? ' in ' + (Math.round(ms / 100) / 10) + ' s' : ''; }
652
+ /** A request that worked but took 3 s or more: a warning, since nothing failed. */
653
+ function slow(method, url, status, t0) {
654
+ if (Date.now() - t0 >= 3000) note('warn', 'Slow request: ' + method + ' ' + shortUrl(url) + ' → ' + status + took(t0), null, 'request');
655
+ }
656
+ if ((TRAIL.request || NUDGE.requests) && window.fetch) {
550
657
  var ofetch = window.fetch;
551
658
  window.fetch = function (input, init) {
552
659
  var p = ofetch.apply(window, arguments);
@@ -554,17 +661,21 @@
554
661
  var url = typeof input === 'string' ? input : input && (input.url || String(input));
555
662
  if (url && !ours(url)) {
556
663
  var method = String(init && init.method || input && input.method || 'GET').toUpperCase();
664
+ var t0 = Date.now();
557
665
  p.then(function (res) {
558
- if (!res.ok && res.type !== 'opaque') note('request', method + ' ' + shortUrl(url) + ' → ' + res.status);
666
+ if (!res.ok && res.type !== 'opaque') { note('request', method + ' ' + shortUrl(url) + ' → ' + res.status + took(t0)); requestFailed(res.status); }
667
+ else slow(method, url, res.status, t0);
559
668
  }, function (err) {
560
- if (!(err && err.name === 'AbortError')) note('request', method + ' ' + shortUrl(url) + ' → failed (' + (navigator.onLine === false ? 'offline' : 'network error') + ')');
669
+ if (err && err.name === 'AbortError') return;
670
+ note('request', method + ' ' + shortUrl(url) + ' → failed (' + (navigator.onLine === false ? 'offline' : 'network error') + ')' + took(t0));
671
+ requestFailed(0);
561
672
  });
562
673
  }
563
674
  } catch (e) { /* ignore */ }
564
675
  return p;
565
676
  };
566
677
  }
567
- if (TRAIL.request && window.XMLHttpRequest) {
678
+ if ((TRAIL.request || NUDGE.requests) && window.XMLHttpRequest) {
568
679
  var XP = XMLHttpRequest.prototype, xopen = XP.open, xsend = XP.send;
569
680
  XP.open = function (m, u) {
570
681
  try { this.__heresay = { m: String(m || 'GET').toUpperCase(), u: String(u) }; } catch (e) { /* ignore */ }
@@ -574,11 +685,12 @@
574
685
  var x = this, r = x.__heresay;
575
686
  try {
576
687
  if (r && !ours(r.u)) {
577
- var aborted = false;
688
+ var aborted = false, t0 = Date.now();
578
689
  x.addEventListener('abort', function () { aborted = true; });
579
690
  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)');
691
+ if (x.status >= 400) { note('request', r.m + ' ' + shortUrl(r.u) + ' → ' + x.status + took(t0)); requestFailed(x.status); }
692
+ else if (x.status === 0 && !aborted) { note('request', r.m + ' ' + shortUrl(r.u) + ' → failed (network error)' + took(t0)); requestFailed(0); }
693
+ else if (x.status) slow(r.m, r.u, x.status, t0);
582
694
  });
583
695
  }
584
696
  } catch (e) { /* ignore */ }
@@ -618,11 +730,138 @@
618
730
  };
619
731
  });
620
732
  }
733
+ if (TRAIL.error) {
734
+ // Something the page's own security policy blocked: often why a script or an embed is missing.
735
+ document.addEventListener('securitypolicyviolation', function (e) {
736
+ note('error', 'Blocked by the Content Security Policy (' + (e.effectiveDirective || e.violatedDirective) + '): ' +
737
+ (/^https?:/.test(e.blockedURI) ? shortUrl(e.blockedURI) : e.blockedURI || 'inline'));
738
+ });
739
+ // The page stopped answering: a long task of a second or more.
740
+ try {
741
+ new PerformanceObserver(function (l) {
742
+ l.getEntries().forEach(function (t) {
743
+ if (t.duration >= 1000) note('warn', 'The page froze for ' + (Math.round(t.duration / 100) / 10) + ' s');
744
+ });
745
+ }).observe({ type: 'longtask', buffered: true });
746
+ } catch (e) { /* not in this browser */ }
747
+ // What the app told the person: alerts, as screen readers announce them. Checked at most every
748
+ // 300 ms, only when the page changes.
749
+ var shown = typeof WeakMap === 'function' ? new WeakMap() : null, alertTimer = null;
750
+ var checkAlerts = function () {
751
+ alertTimer = null;
752
+ document.querySelectorAll('[role=alert],[role=alertdialog],[aria-live=assertive]').forEach(function (a) {
753
+ if (host.contains(a) || a.closest('[data-heresay-private]')) return;
754
+ var t = (a.getAttribute('aria-label') || a.textContent || '').replace(/\s+/g, ' ').trim();
755
+ if (shown.get(a) === t) return;
756
+ shown.set(a, t);
757
+ if (t) note('warn', 'The app showed: "' + (t.length > 120 ? t.slice(0, 119) + '…' : t) + '"');
758
+ });
759
+ };
760
+ if (shown && window.MutationObserver) {
761
+ new MutationObserver(function () { if (!alertTimer) alertTimer = setTimeout(checkAlerts, 300); })
762
+ .observe(document.documentElement, { childList: true, subtree: true, characterData: true });
763
+ }
764
+ }
621
765
  if (TRAIL.state) {
622
766
  window.addEventListener('offline', function () { note('state', 'Went offline'); });
623
767
  window.addEventListener('online', function () { note('state', 'Back online'); });
768
+ // Leaving the tab and coming back: a session can expire, a socket drop, while they are away.
769
+ var hiddenAt = 0;
770
+ document.addEventListener('visibilitychange', function () {
771
+ if (document.visibilityState === 'hidden') { hiddenAt = Date.now(); return; }
772
+ var s = hiddenAt ? Math.round((Date.now() - hiddenAt) / 1000) : 0;
773
+ hiddenAt = 0;
774
+ if (s >= 5) note('state', 'Came back to the tab after ' + (s >= 60 ? Math.floor(s / 60) + ':' + ('0' + s % 60).slice(-2) + ' min' : s + ' s'));
775
+ });
624
776
  }
625
777
 
778
+ // ---- offering help ---------------------------------------------------------------------
779
+
780
+ /**
781
+ * data-nudge: when someone seems stuck, a small note by the button asks whether they want to
782
+ * tell the team. Off unless the host turns it on: it is the host's page it appears on. Watched
783
+ * here on the device and never sent anywhere; it only offers the form, with the trail.
784
+ *
785
+ * clicks the same button or link pressed 3 times in 10 s, and the page did not change
786
+ * errors an uncaught error or failed promise within 5 s of a click
787
+ * requests 2 requests failing (5xx or no answer) within 30 s, while online
788
+ *
789
+ * At most once per tab, and not for 7 days after "Not now".
790
+ */
791
+ var DEAD_WAIT = 1500, DEAD_SPAN = 10000, DEAD_COUNT = 3;
792
+ var lastPress = 0;
793
+
794
+ // Clicks that did nothing: no change to the page and no new address within 1.5 s. Buttons and
795
+ // links only; fields, checkboxes and sliders change without touching the page.
796
+ var PRESSABLE = 'a[href],button,input[type=button],input[type=submit],input[type=reset],[role=button],[role=link],[role=menuitem],[role=tab],summary';
797
+ var presses = [], pending = 0, pageWatch = null;
798
+ function pageChanged() {
799
+ var now = Date.now();
800
+ presses.forEach(function (p) { if (now - p.at <= DEAD_WAIT) p.changed = true; });
801
+ }
802
+ function judge(p) {
803
+ if (--pending === 0 && pageWatch) { pageWatch.disconnect(); pageWatch = null; }
804
+ if (p.changed || location.href !== p.href) return;
805
+ p.dead = true;
806
+ var cut = Date.now() - DEAD_SPAN;
807
+ presses = presses.filter(function (q) { return q.at >= cut; });
808
+ var same = presses.filter(function (q) { return q.dead && q.el === p.el; });
809
+ if (same.length >= DEAD_COUNT) { presses = []; trouble('clicks'); }
810
+ }
811
+ if (NUDGE.clicks || NUDGE.errors) {
812
+ // pointerdown, not click: a disabled button gets no click, and it is the classic one to press again.
813
+ document.addEventListener('pointerdown', function (e) {
814
+ if (!e.isPrimary || e.button > 0 || !host || host.contains(e.target) || e.target === host) return;
815
+ lastPress = Date.now();
816
+ if (!NUDGE.clicks || !e.target.closest) return;
817
+ var c = e.target.closest(PRESSABLE);
818
+ if (!c || c.closest('[data-feedback-sdk]')) return;
819
+ // A new tab, a download, an email: the page stays as it was, and that is fine.
820
+ if (c.tagName === 'A' && (/^(mailto|tel|sms):/i.test(c.getAttribute('href')) || c.hasAttribute('download')
821
+ || (c.target && c.target !== '_self'))) return;
822
+ var p = { el: c, at: lastPress, href: location.href, changed: false, dead: false };
823
+ presses.push(p);
824
+ if (!pageWatch && window.MutationObserver) {
825
+ pageWatch = new MutationObserver(pageChanged);
826
+ pageWatch.observe(document.documentElement, { childList: true, subtree: true, attributes: true, characterData: true });
827
+ }
828
+ pending++;
829
+ setTimeout(function () { judge(p); }, DEAD_WAIT);
830
+ }, true);
831
+ }
832
+
833
+ // Errors right after a click. Not from browser extensions, not the browser's ResizeObserver
834
+ // notice, not cross-origin "Script error." with nothing to go on.
835
+ function appError(msg, where) {
836
+ if (!lastPress || Date.now() - lastPress > 5000) return false;
837
+ if (/ResizeObserver loop/.test(msg || '')) return false;
838
+ if (/^(chrome|moz|safari(-web)?)-extension:/.test(where || '')) return false;
839
+ if (where && script.src && where.indexOf(script.src.split(/[?#]/)[0]) === 0) return false;
840
+ return true;
841
+ }
842
+ if (NUDGE.errors) {
843
+ window.addEventListener('error', function (e) {
844
+ if (e.target && e.target !== window) return; // a file that did not load
845
+ if (!e.filename && !e.error) return;
846
+ if (appError(e.message, e.filename)) trouble('errors');
847
+ }, true);
848
+ window.addEventListener('unhandledrejection', function (e) {
849
+ var r = e.reason, stack = r && r.stack ? String(r.stack) : '';
850
+ if (/(chrome|moz|safari(-web)?)-extension:/.test(stack)) return;
851
+ if (appError(r && r.message, '')) trouble('errors');
852
+ });
853
+ }
854
+
855
+ // Requests failing in a row: the server, or the way to it. A 4xx is usually the app answering.
856
+ var fails = [];
857
+ function requestFailed(status) {
858
+ if (!NUDGE.requests || navigator.onLine === false || (status && status < 500)) return;
859
+ var now = Date.now();
860
+ fails = fails.filter(function (t) { return now - t < 30000; }).concat(now);
861
+ if (fails.length >= 2) { fails = []; trouble('requests'); }
862
+ }
863
+ function trouble(why) { if (NUDGE[why]) offerHelp(); }
864
+
626
865
  // ---- network ---------------------------------------------------------------------------
627
866
 
628
867
  // A 404 means the key is unknown: the app was deleted from the dashboard, or the key is
@@ -719,6 +958,8 @@
719
958
  '.intro .by{margin-top:12px;padding-top:8px}',
720
959
  '@keyframes fb-in{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}',
721
960
  '@media (prefers-reduced-motion:reduce){.intro{animation:none}}',
961
+ // offering help: the introduction's bubble; with no button to point at, it sits in its place
962
+ '.intro.free:after{display:none}.intro.free.b{bottom:var(--fb-y)}.intro.free.t{top:var(--fb-y)}',
722
963
  '.mark{display:inline-flex;color:var(--fb-mark)}.mark svg{display:block}.eye{fill:var(--fb-eye)}',
723
964
  '.dot{width:8px;height:8px;border-radius:50%;background:var(--fb-acc)}',
724
965
 
@@ -889,6 +1130,7 @@
889
1130
  var off = !revealed || hiddenHere();
890
1131
  if (off) fab.setAttribute('hidden', ''); else fab.removeAttribute('hidden');
891
1132
  if (off && bubble) { bubble.remove(); bubble = null; }
1133
+ if (off && nudgeEl) { nudgeEl.remove(); nudgeEl = null; }
892
1134
  }
893
1135
  /** Can the reporter see the button right now? The introduction points at it. */
894
1136
  function fabShowing() {
@@ -910,6 +1152,7 @@
910
1152
  if (dead) return;
911
1153
  if (scrim) { if (which) { view = which; renderPanel(); } return; }
912
1154
  if (bubble) { bubble.remove(); bubble = null; }
1155
+ if (nudgeEl) { nudgeEl.remove(); nudgeEl = null; }
913
1156
  lastFocus = document.activeElement;
914
1157
  view = which || (unseen() ? 'mine' : 'new');
915
1158
  var cls = PANEL === 'center' ? 'center' : PLACE + (PANEL === 'sheet' ? ' sheet' : '');
@@ -1049,7 +1292,10 @@
1049
1292
  }));
1050
1293
  box.appendChild(el('label', { class: 'switch' }, [on, el('span', { text: S.attachTrail })]));
1051
1294
  box.appendChild(el('div', { class: 'chips' }, chips));
1052
- box.appendChild(el('details', {}, [el('summary', { text: S.seeTrail }), el('p', { class: 'small', text: S.trailHint }), list]));
1295
+ var c = context();
1296
+ var device = [c.device, c.screen, c.theme, c.locale, c.timezone, c.network, c.settings].filter(Boolean).join(' · ');
1297
+ box.appendChild(el('details', {}, [el('summary', { text: S.seeTrail }), el('p', { class: 'small', text: S.trailHint }), list,
1298
+ device ? el('p', { class: 'small', text: S.alsoSent + device }) : null]));
1053
1299
  return box;
1054
1300
  }
1055
1301
 
@@ -1172,6 +1418,60 @@
1172
1418
  return true;
1173
1419
  }
1174
1420
 
1421
+ // ---- offering help: the note -----------------------------------------------------------
1422
+
1423
+ // Someone seems stuck (data-nudge), or the app says so (nudge()). A note by the button, which
1424
+ // takes no focus and goes by itself after 15 s unless it is being read. "Tell the team" opens
1425
+ // the form as Broken, with the trail. At most once per tab; "Not now" quiets it for 7 days.
1426
+ var NUDGE_NO = 'fbsdk.nudge.no.' + KEY, NUDGE_TAB = 'fbsdk.nudged.' + KEY, NUDGE_REST = 7 * 864e5;
1427
+ var nudgeEl = null;
1428
+ /** True if this tab was already offered help; otherwise marks it. */
1429
+ function offeredInTab() {
1430
+ try {
1431
+ if (PREVIEW) throw 0;
1432
+ if (sessionStorage.getItem(NUDGE_TAB)) return true;
1433
+ sessionStorage.setItem(NUDGE_TAB, '1');
1434
+ } catch (e) {
1435
+ if (mem[NUDGE_TAB]) return true;
1436
+ mem[NUDGE_TAB] = '1';
1437
+ }
1438
+ return false;
1439
+ }
1440
+ function offerHelp() {
1441
+ if (dead || scrim || bubble || nudgeEl || !host.isConnected || hiddenHere() || document.visibilityState === 'hidden') return false;
1442
+ if (Date.now() - (+load(NUDGE_NO) || 0) < NUDGE_REST) return false;
1443
+ if (offeredInTab()) return false;
1444
+ var timer = null;
1445
+ var done = function (no) {
1446
+ clearTimeout(timer);
1447
+ if (no) save(NUDGE_NO, String(Date.now()));
1448
+ if (nudgeEl) { nudgeEl.remove(); nudgeEl = null; }
1449
+ };
1450
+ var later = function () { clearTimeout(timer); timer = setTimeout(function () { done(false); }, 15000); };
1451
+ var stay = function () { clearTimeout(timer); };
1452
+ nudgeEl = el('div', {
1453
+ class: 'intro nudge ' + PLACE + ' st-' + STYLE + (fabShowing() ? '' : ' free'),
1454
+ role: 'status', 'aria-label': S.nudgeAria,
1455
+ onpointerenter: stay, onpointerleave: later, onfocusin: stay, onfocusout: later,
1456
+ onkeydown: function (e) { if (e.key === 'Escape') done(true); },
1457
+ }, [
1458
+ el('b', { text: S.nudgeTitle }),
1459
+ el('p', { text: S.nudgeBody }),
1460
+ el('div', { class: 'row' }, [
1461
+ el('button', { class: 'link', type: 'button', text: S.nudgeNo, onclick: function () { done(true); } }),
1462
+ el('button', { class: 'send', type: 'button', text: S.nudgeYes, onclick: function () {
1463
+ done(false);
1464
+ if (!state.type && OFFERED.some(function (t) { return t.id === 'broken'; })) state.type = 'broken';
1465
+ open('new');
1466
+ } }),
1467
+ ]),
1468
+ byline(false),
1469
+ ]);
1470
+ root.appendChild(nudgeEl);
1471
+ later();
1472
+ return true;
1473
+ }
1474
+
1175
1475
  function mount() {
1176
1476
  if (dead) return;
1177
1477
  if (!host.isConnected) document.body.appendChild(host);
@@ -1205,6 +1505,9 @@
1205
1505
  openPreferences: function () { if (PREFS_TAB) open('prefs'); },
1206
1506
  /** Show the one-time introduction now. False if it was already shown on this device. */
1207
1507
  introduce: function (o) { return introduce(o); },
1508
+ /** The app saw trouble itself (an error screen, a retry that failed): offer to report it.
1509
+ * Works without data-nudge; the same limits apply. False if it did not show. */
1510
+ nudge: function () { return offerHelp(); },
1208
1511
  /** on('sent', fn): fn({ id, type }) after each report is sent. Returns a function that stops it. */
1209
1512
  on: function (event, fn) {
1210
1513
  if (event !== 'sent' || typeof fn !== 'function') return function () {};