create-heresay 0.2.21 → 0.2.23

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.
@@ -33,7 +33,7 @@
33
33
  * a report; see "the trail" below. data-heresay-private on any element
34
34
  * keeps its text out of click records.
35
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
36
+ * (clicks, errors, requests; stalled, circles, refused). When someone seems stuck, a small note
37
37
  * by the button asks if they want to tell the team. See "offering
38
38
  * help" below.
39
39
  * Optional calls, any time after the script runs:
@@ -43,7 +43,7 @@
43
43
  * Feedback.open({ type, text }) type and text optional: starts a report already filled in
44
44
  * Feedback.on("sent", fn) fn({ id, type }) after each report is sent; returns an off()
45
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
46
+ * Feedback.nudge({ stuck }) the app saw trouble itself: offer to report it, as data-nudge does
47
47
  * data-preview for the dashboard's designer: nothing is sent or stored
48
48
  * Feedback.openPreferences() a note about their setup, and a name and email if not signed in
49
49
  *
@@ -89,8 +89,8 @@
89
89
  what: 'What is it?', whatHappened: 'What happened?', ph: 'What happened, or what would you change?',
90
90
  send: 'Send', sending: 'Sending…',
91
91
  pickType: 'Pick what kind of report this is.', sayWhat: 'Say what happened.', cantSend: 'Could not send. Try again.',
92
- attachedPrefs: 'This page, the app version and your preferences are attached.',
93
- 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.',
94
94
  types: {
95
95
  broken: ['Broken', 'Something does not work'],
96
96
  confusing: ['Confusing', 'I could not tell how to do something'],
@@ -114,9 +114,9 @@
114
114
  got: 'Got it', tryIt: 'Try it',
115
115
  attachTrail: 'Attach what happened',
116
116
  trailHint: 'Recent pages, clicks and errors in this app. Never what you typed.',
117
- seeTrail: 'See it',
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',
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
+ nudgeStuckTitle: 'Stuck on something?', nudgeStuckBody: 'If something here isn’t clear, tell the team. A real person reads it.', 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',
120
120
  sentTo: 'Sent to this app’s team', powered: 'Powered by Heresay',
121
121
  },
122
122
  fr: {
@@ -127,8 +127,8 @@
127
127
  what: 'De quoi s’agit-il ?', whatHappened: 'Que s’est-il passé ?', ph: 'Que s’est-il passé, ou que changeriez-vous ?',
128
128
  send: 'Envoyer', sending: 'Envoi…',
129
129
  pickType: 'Choisissez le type de signalement.', sayWhat: 'Dites ce qui s’est passé.', cantSend: 'Envoi impossible. Réessayez.',
130
- attachedPrefs: 'Cette page, la version de l’app et vos préférences sont jointes.',
131
- 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.',
132
132
  types: {
133
133
  broken: ['Cassé', 'Quelque chose ne marche pas'],
134
134
  confusing: ['Déroutant', 'Je ne voyais pas comment faire'],
@@ -152,9 +152,9 @@
152
152
  got: 'Compris', tryIt: 'Essayer',
153
153
  attachTrail: 'Joindre ce qui s’est passé',
154
154
  trailHint: 'Pages, clics et erreurs récents dans cette app. Jamais ce que vous avez saisi.',
155
- seeTrail: 'Voir',
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',
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
+ nudgeStuckTitle: 'Bloqué quelque part ?', nudgeStuckBody: 'Si quelque chose n’est pas clair ici, dites-le à l’équipe. Une vraie personne le lit.', 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',
158
158
  sentTo: 'Envoyé à l’équipe de cette app', powered: 'Propulsé par Heresay',
159
159
  },
160
160
  ta: {
@@ -165,8 +165,8 @@
165
165
  what: 'இது என்ன வகை?', whatHappened: 'என்ன நடந்தது?', ph: 'என்ன நடந்தது, அல்லது எதை மாற்ற விரும்புகிறீர்கள்?',
166
166
  send: 'அனுப்பு', sending: 'அனுப்புகிறது…',
167
167
  pickType: 'இது எந்த வகைப் புகார் என்பதைத் தேர்ந்தெடுக்கவும்.', sayWhat: 'என்ன நடந்தது என்று சொல்லுங்கள்.', cantSend: 'அனுப்ப முடியவில்லை. மீண்டும் முயலவும்.',
168
- attachedPrefs: 'இந்தப் பக்கம், ஆப் பதிப்பு மற்றும் உங்கள் விருப்பங்கள் இணைக்கப்படும்.',
169
- attached: 'இந்தப் பக்கமும் ஆப் பதிப்பும் இணைக்கப்படும்.',
168
+ attachedPrefs: 'இந்தப் பக்கம், ஆப் பதிப்பு, சாதன விவரங்கள் மற்றும் உங்கள் விருப்பங்கள் இணைக்கப்படும்.',
169
+ attached: 'இந்தப் பக்கம், ஆப் பதிப்பு மற்றும் சாதன விவரங்கள் இணைக்கப்படும்.',
170
170
  types: {
171
171
  broken: ['வேலை செய்யவில்லை', 'ஏதோ ஒன்று சரியாக இயங்கவில்லை'],
172
172
  confusing: ['குழப்பமாக உள்ளது', 'எப்படிச் செய்வது என்று புரியவில்லை'],
@@ -190,9 +190,9 @@
190
190
  got: 'சரி', tryIt: 'முயன்று பாருங்கள்',
191
191
  attachTrail: 'என்ன நடந்தது என்பதையும் இணை',
192
192
  trailHint: 'இந்த ஆப்பில் சமீபத்திய பக்கங்கள், கிளிக்குகள், பிழைகள். நீங்கள் தட்டச்சு செய்தது ஒருபோதும் இல்லை.',
193
- seeTrail: 'பார்',
194
- trail: { page: ['பக்கம்', 'பக்கங்கள்'], click: ['கிளிக்', 'கிளிக்குகள்'], request: ['தோல்வியடைந்த கோரிக்கை', 'தோல்வியடைந்த கோரிக்கைகள்'], error: ['பிழை', 'பிழைகள்'], warn: ['எச்சரிக்கை', 'எச்சரிக்கைகள்'], state: ['இணைப்பு மாற்றம்', 'இணைப்பு மாற்றங்கள்'] },
195
- nudgeAria: 'சிக்கலைத் தெரிவிக்க ஒரு அழைப்பு', nudgeTitle: 'ஏதாவது வேலை செய்யவில்லையா?', nudgeBody: 'என்ன நடந்தது என்று குழுவிடம் சொல்லுங்கள். ஒருவர் அதைப் படிப்பார்.', nudgeYes: 'குழுவிடம் சொல்', nudgeNo: 'இப்போது வேண்டாம்',
193
+ seeTrail: 'பார்', alsoSent: 'இவையும் அனுப்பப்படும்: ',
194
+ trail: { page: ['பக்கம்', 'பக்கங்கள்'], click: ['கிளிக்', 'கிளிக்குகள்'], request: ['தோல்வியடைந்த கோரிக்கை', 'தோல்வியடைந்த கோரிக்கைகள்'], error: ['பிழை', 'பிழைகள்'], warn: ['எச்சரிக்கை', 'எச்சரிக்கைகள்'], state: ['சாதன நிகழ்வு', 'சாதன நிகழ்வுகள்'] },
195
+ nudgeStuckTitle: 'எங்காவது சிக்கிக்கொண்டீர்களா?', nudgeStuckBody: 'இங்கே ஏதாவது புரியவில்லை என்றால், குழுவிடம் சொல்லுங்கள். ஒருவர் அதைப் படிப்பார்.', nudgeAria: 'சிக்கலைத் தெரிவிக்க ஒரு அழைப்பு', nudgeTitle: 'ஏதாவது வேலை செய்யவில்லையா?', nudgeBody: 'என்ன நடந்தது என்று குழுவிடம் சொல்லுங்கள். ஒருவர் அதைப் படிப்பார்.', nudgeYes: 'குழுவிடம் சொல்', nudgeNo: 'இப்போது வேண்டாம்',
196
196
  sentTo: 'இந்த ஆப்பின் குழுவுக்கு அனுப்பப்படும்', powered: 'Heresay மூலம் இயங்குகிறது',
197
197
  },
198
198
  hi: {
@@ -203,8 +203,8 @@
203
203
  what: 'यह क्या है?', whatHappened: 'क्या हुआ?', ph: 'क्या हुआ, या आप क्या बदलना चाहेंगे?',
204
204
  send: 'भेजें', sending: 'भेजा जा रहा है…',
205
205
  pickType: 'चुनें कि यह किस तरह की रिपोर्ट है।', sayWhat: 'बताइए क्या हुआ।', cantSend: 'भेजा नहीं जा सका। फिर से कोशिश करें।',
206
- attachedPrefs: 'यह पेज, ऐप का वर्शन और आपकी प्राथमिकताएँ साथ भेजी जाती हैं।',
207
- attached: 'यह पेज और ऐप का वर्शन साथ भेजे जाते हैं।',
206
+ attachedPrefs: 'यह पेज, ऐप का वर्शन, डिवाइस की जानकारी और आपकी प्राथमिकताएँ साथ भेजी जाती हैं।',
207
+ attached: 'यह पेज, ऐप का वर्शन और डिवाइस की जानकारी साथ भेजी जाती है।',
208
208
  types: {
209
209
  broken: ['टूटा हुआ', 'कुछ काम नहीं कर रहा'],
210
210
  confusing: ['उलझन भरा', 'समझ नहीं आया कि कैसे करें'],
@@ -228,9 +228,9 @@
228
228
  got: 'ठीक है', tryIt: 'आज़माएँ',
229
229
  attachTrail: 'क्या हुआ, वह भी भेजें',
230
230
  trailHint: 'इस ऐप में हाल के पेज, क्लिक और त्रुटियाँ। आपने जो टाइप किया, वह कभी नहीं।',
231
- seeTrail: 'देखें',
232
- trail: { page: ['पेज', 'पेज'], click: ['क्लिक', 'क्लिक'], request: ['विफल अनुरोध', 'विफल अनुरोध'], error: ['त्रुटि', 'त्रुटियाँ'], warn: ['चेतावनी', 'चेतावनियाँ'], state: ['कनेक्शन बदलाव', 'कनेक्शन बदलाव'] },
233
- nudgeAria: 'समस्या बताने का सुझाव', nudgeTitle: 'कुछ काम नहीं कर रहा?', nudgeBody: 'टीम को बताइए क्या हुआ। इसे कोई इंसान पढ़ता है।', nudgeYes: 'टीम को बताएँ', nudgeNo: 'अभी नहीं',
231
+ seeTrail: 'देखें', alsoSent: 'यह भी भेजा जाता है: ',
232
+ trail: { page: ['पेज', 'पेज'], click: ['क्लिक', 'क्लिक'], request: ['विफल अनुरोध', 'विफल अनुरोध'], error: ['त्रुटि', 'त्रुटियाँ'], warn: ['चेतावनी', 'चेतावनियाँ'], state: ['डिवाइस घटना', 'डिवाइस घटनाएँ'] },
233
+ nudgeStuckTitle: 'कहीं अटक गए?', nudgeStuckBody: 'अगर यहाँ कुछ साफ़ नहीं है, तो टीम को बताइए। इसे कोई इंसान पढ़ता है।', nudgeAria: 'समस्या बताने का सुझाव', nudgeTitle: 'कुछ काम नहीं कर रहा?', nudgeBody: 'टीम को बताइए क्या हुआ। इसे कोई इंसान पढ़ता है।', nudgeYes: 'टीम को बताएँ', nudgeNo: 'अभी नहीं',
234
234
  sentTo: 'इस ऐप की टीम को भेजा जाता है', powered: 'Heresay द्वारा संचालित',
235
235
  },
236
236
  };
@@ -413,15 +413,45 @@
413
413
  page_title: (document.title || '').trim() || null,
414
414
  page_url: pageUrl(),
415
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,
416
425
  };
417
426
  }
418
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
+
419
449
  // ---- the trail -------------------------------------------------------------------------
420
450
 
421
451
  /**
422
452
  * What happened in the app before a report: pages, clicks, requests that failed, errors. Kept
423
- * in memory on this device only (the newest 30, for 5 minutes) and sent only with a report,
424
- * only if the reporter leaves "Attach what happened" on. Never what anyone typed, never request
453
+ * on this device only, in memory and this tab's sessionStorage (the newest 50, for 5 minutes),
454
+ * and sent only with a report, only if the reporter leaves "Attach what happened" on. Never what anyone typed, never request
425
455
  * or response bodies or headers, never query strings. Nothing is recorded inside the widget.
426
456
  */
427
457
  var TRAIL_PARTS = { pages: 'page', clicks: 'click', requests: 'request', errors: 'error' };
@@ -434,9 +464,12 @@
434
464
  if (on.page || on.request || on.error) on.state = true;
435
465
  return on;
436
466
  })();
437
- var TRAIL_MAX = 30, TRAIL_AGE = 5 * 60000;
467
+ var TRAIL_MAX = 50, TRAIL_AGE = 5 * 60000;
468
+ // Pages visited and when someone last typed, for data-nudge ("offering help"). Here because the
469
+ // page watcher below records the first page before that part of the script runs.
470
+ var visits = [], typedAt = 0;
438
471
  // data-nudge, read here because the request watchers below serve both. See "offering help".
439
- var NUDGE_SIGNALS = ['clicks', 'errors', 'requests'];
472
+ var NUDGE_SIGNALS = ['clicks', 'errors', 'requests', 'stalled', 'circles', 'refused'];
440
473
  var NUDGE = (function () {
441
474
  var v = attr('nudge').toLowerCase(), on = {};
442
475
  if (PREVIEW || !v || /^(off|none|false|no)$/.test(v)) return on;
@@ -463,17 +496,53 @@
463
496
  }
464
497
 
465
498
  var noting = false;
466
- function note(kind, text, detail) {
467
- if (!TRAIL[kind] || noting) return;
499
+ /** `part` is the data-trail part that allows it, when that isn't the kind's own. */
500
+ function note(kind, text, detail, part) {
501
+ if (!(part ? TRAIL[part] : TRAIL[kind]) || noting) return;
468
502
  noting = true;
469
503
  try {
470
504
  text = scrub(text, 200);
471
505
  if (!text) return;
472
506
  var now = Date.now(), last = trail[trail.length - 1];
473
- if (last && last.kind === kind && last.text === text) { last.n++; last.at = now; return; }
474
- trail.push({ kind: kind, at: now, text: text, detail: detail ? scrub(detail, 600) : null, n: 1 });
507
+ keep();
508
+ if (last && last.kind === kind && last.text === text) { last.n++; last.at = now; return last; }
509
+ var e = { kind: kind, at: now, text: text, detail: detail ? scrub(detail, 600) : null, n: 1 };
510
+ trail.push(e);
475
511
  if (trail.length > TRAIL_MAX) trail.shift();
476
- } catch (e) { /* never break the app over a record */ } finally { noting = false; }
512
+ return e;
513
+ } catch (x) { /* never break the app over a record */ } finally { noting = false; }
514
+ }
515
+
516
+ // The trail outlives a reload or a new page in this tab: kept in sessionStorage, which only this
517
+ // tab can read and the browser clears when it closes. So a page that froze or went blank and was
518
+ // reloaded still has what happened before it, and so does a site whose pages are separate loads.
519
+ var TRAIL_KEY = 'fbsdk.trail.' + KEY, keepTimer = null;
520
+ function keep() {
521
+ if (PREVIEW || keepTimer) return;
522
+ keepTimer = setTimeout(keepNow, 300);
523
+ }
524
+ function keepNow() {
525
+ clearTimeout(keepTimer); keepTimer = null;
526
+ try { sessionStorage.setItem(TRAIL_KEY, JSON.stringify(recentTrail())); } catch (e) { /* full or blocked */ }
527
+ }
528
+ if (!PREVIEW && Object.keys(TRAIL).length) {
529
+ try {
530
+ var kept = JSON.parse(sessionStorage.getItem(TRAIL_KEY) || '[]'), cut = Date.now() - TRAIL_AGE;
531
+ trail = (Array.isArray(kept) ? kept : []).filter(function (e) {
532
+ return e && typeof e.text === 'string' && TRAIL[e.kind] && e.at >= cut && e.at <= Date.now();
533
+ }).slice(-TRAIL_MAX);
534
+ } catch (e) { trail = []; }
535
+ var nav = window.performance && performance.getEntriesByType && performance.getEntriesByType('navigation')[0];
536
+ if (trail.length && nav && nav.type === 'reload') note('state', 'The page was reloaded');
537
+ window.addEventListener('pagehide', keepNow);
538
+ }
539
+
540
+ /** The first visit after the app's version changed: what broke often broke with the update. */
541
+ function versionSeen(v) {
542
+ if (!v || PREVIEW) return;
543
+ var k = 'fbsdk.version.' + KEY, seen = load(k);
544
+ if (seen && seen !== v) note('state', 'First visit since the app updated from ' + seen + ' to ' + v);
545
+ save(k, v);
477
546
  }
478
547
  function recentTrail() {
479
548
  var cut = Date.now() - TRAIL_AGE;
@@ -496,7 +565,9 @@
496
565
  return (x.origin === location.origin ? '' : x.origin) + x.pathname;
497
566
  } catch (e) { return String(u).split(/[?#]/)[0]; }
498
567
  }
499
- function ours(u) { try { return new URL(u, location.href).href.indexOf(API) === 0; } catch (e) { return false; } }
568
+ // data-api may be relative ('/v1'), so both sides are made absolute before comparing.
569
+ var API_ABS = (function () { try { return new URL(API, location.href).href; } catch (e) { return API; } })();
570
+ function ours(u) { try { return new URL(u, location.href).href.indexOf(API_ABS) === 0; } catch (e) { return false; } }
500
571
  function frames(err) {
501
572
  var s = err && err.stack ? String(err.stack) : '';
502
573
  var f = s.split('\n').filter(function (l) { return /^\s*at\s|@/.test(l); }).slice(0, 3)
@@ -518,12 +589,23 @@
518
589
 
519
590
  // Pages: any router changes the address through history, so watch that.
520
591
  var lastWhere = null;
521
- function onPage() {
592
+ function titled(w) {
593
+ var t = (document.title || '').replace(/\s+/g, ' ').trim();
594
+ return w + (t ? ' "' + (t.length > 60 ? t.slice(0, 59) + '…' : t) + '"' : '');
595
+ }
596
+ function onPage(first) {
522
597
  var w = location.pathname + location.hash;
523
- if (w !== lastWhere) { lastWhere = w; note('page', w); }
598
+ if (w === lastWhere) return;
599
+ lastWhere = w;
600
+ visited(w);
601
+ if (first === true) { note('page', titled(w)); return; }
602
+ // Single-page apps set the title just after the address: the entry goes in now, in order,
603
+ // and gets the title a moment later.
604
+ var e = note('page', w);
605
+ if (e) setTimeout(function () { var t = scrub(titled(w), 200); if (t) e.text = t; }, 150);
524
606
  }
525
- if (TRAIL.page) {
526
- onPage();
607
+ if (TRAIL.page || NUDGE.circles) {
608
+ onPage(true);
527
609
  ['pushState', 'replaceState'].forEach(function (m) {
528
610
  var orig = history[m];
529
611
  if (typeof orig !== 'function') return;
@@ -539,7 +621,8 @@
539
621
 
540
622
  // Clicks: what was clicked, by its label. Never a field's value.
541
623
  var CLICKABLE = 'a,button,input,select,textarea,label,summary,[role=button],[role=link],[role=tab],[role=menuitem],[role=checkbox],[role=switch],[role=option]';
542
- function clicked(t) {
624
+ /** `bare` leaves out where it is. */
625
+ function clicked(t, bare) {
543
626
  var hit = t.closest && t.closest(CLICKABLE), n = hit || t;
544
627
  if (!n.tagName) return null;
545
628
  var tag = n.tagName.toLowerCase(), type = (n.getAttribute('type') || '').toLowerCase();
@@ -555,7 +638,24 @@
555
638
  || n.getAttribute('title') || n.getAttribute('alt') || '';
556
639
  name = name.replace(/\s+/g, ' ').trim();
557
640
  if (name.length > 40) name = name.slice(0, 39) + '…';
558
- return what + (name ? ' "' + name + '"' : '');
641
+ return what + (name ? ' "' + name + '"' : '') + (bare ? '' : where(n));
642
+ }
643
+
644
+ /** The dialog, form, menu or region a control is in, by its name: ' in dialog "Edit profile"'. */
645
+ 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]';
646
+ function where(n) {
647
+ var a = n.parentElement && n.parentElement.closest(AREAS);
648
+ if (!a || a.closest('[data-heresay-private]')) return '';
649
+ var tag = a.tagName.toLowerCase(), role = a.getAttribute('role');
650
+ var kind = role === 'alertdialog' ? 'dialog' : role === 'navigation' || tag === 'nav' ? 'navigation'
651
+ : role === 'tabpanel' ? 'tab' : role === 'search' ? 'search' : role || (tag === 'aside' ? 'sidebar' : tag === 'section' ? 'section' : tag);
652
+ var by = a.getAttribute('aria-labelledby');
653
+ var label = a.getAttribute('aria-label')
654
+ || (by && by.split(/\s+/).map(function (id) { var x = document.getElementById(id); return x ? x.textContent : ''; }).join(' '))
655
+ || ((a.querySelector('h1,h2,h3,legend') || {}).textContent) || '';
656
+ label = label.replace(/\s+/g, ' ').trim();
657
+ if (label.length > 30) label = label.slice(0, 29) + '…';
658
+ return ' in ' + kind + (label ? ' "' + label + '"' : '');
559
659
  }
560
660
  if (TRAIL.click) {
561
661
  document.addEventListener('click', function (e) {
@@ -564,8 +664,35 @@
564
664
  }, true);
565
665
  }
566
666
 
567
- // Requests: only the ones that failed, by method, path and status.
568
- if ((TRAIL.request || NUDGE.requests) && window.fetch) {
667
+ // Forms: sent, and the fields the browser refused, by their label and why. Never their value.
668
+ var WHY = { valueMissing: 'is required', typeMismatch: 'is not in the right format', patternMismatch: 'does not match the format asked for',
669
+ tooShort: 'is too short', tooLong: 'is too long', rangeUnderflow: 'is too low', rangeOverflow: 'is too high',
670
+ stepMismatch: 'is not an allowed value', badInput: 'could not be read' };
671
+ if (TRAIL.click) {
672
+ document.addEventListener('submit', function (e) {
673
+ var f = e.target;
674
+ if (!f || !f.tagName || host.contains(f)) return;
675
+ var name = f.closest('[data-heresay-private]') ? '' : (f.getAttribute('aria-label') || f.getAttribute('name') || ((f.querySelector('h1,h2,h3,legend') || {}).textContent) || '');
676
+ name = name.replace(/\s+/g, ' ').trim().slice(0, 40);
677
+ note('click', 'form' + (name ? ' "' + name + '"' : '') + ' sent');
678
+ }, true);
679
+ document.addEventListener('invalid', function (e) {
680
+ var t = e.target;
681
+ if (!t || !t.validity || host.contains(t)) return;
682
+ var why = Object.keys(WHY).filter(function (k) { return t.validity[k]; })[0];
683
+ note('warn', clicked(t, true) + ' ' + (WHY[why] || 'was refused'), null, 'click');
684
+ }, true);
685
+ }
686
+
687
+ // Requests: the ones that failed, and the ones so slow someone would notice, by method, path,
688
+ // status and how long they took.
689
+ /** ' in 2.4 s', past a second; quicker than that, the time says nothing. */
690
+ function took(t0) { var ms = Date.now() - t0; return ms >= 1000 ? ' in ' + (Math.round(ms / 100) / 10) + ' s' : ''; }
691
+ /** A request that worked but took 3 s or more: a warning, since nothing failed. */
692
+ function slow(method, url, status, t0) {
693
+ if (Date.now() - t0 >= 3000) note('warn', 'Slow request: ' + method + ' ' + shortUrl(url) + ' → ' + status + took(t0), null, 'request');
694
+ }
695
+ if ((TRAIL.request || NUDGE.requests || NUDGE.stalled || NUDGE.circles) && window.fetch) {
569
696
  var ofetch = window.fetch;
570
697
  window.fetch = function (input, init) {
571
698
  var p = ofetch.apply(window, arguments);
@@ -573,11 +700,13 @@
573
700
  var url = typeof input === 'string' ? input : input && (input.url || String(input));
574
701
  if (url && !ours(url)) {
575
702
  var method = String(init && init.method || input && input.method || 'GET').toUpperCase();
703
+ var t0 = Date.now();
576
704
  p.then(function (res) {
577
- if (!res.ok && res.type !== 'opaque') { note('request', method + ' ' + shortUrl(url) + ' → ' + res.status); requestFailed(res.status); }
705
+ if (!res.ok && res.type !== 'opaque') { note('request', method + ' ' + shortUrl(url) + ' → ' + res.status + took(t0)); requestFailed(res.status); }
706
+ else { slow(method, url, res.status, t0); if (method !== 'GET' && method !== 'HEAD') sentSomething(); }
578
707
  }, function (err) {
579
708
  if (err && err.name === 'AbortError') return;
580
- note('request', method + ' ' + shortUrl(url) + ' → failed (' + (navigator.onLine === false ? 'offline' : 'network error') + ')');
709
+ note('request', method + ' ' + shortUrl(url) + ' → failed (' + (navigator.onLine === false ? 'offline' : 'network error') + ')' + took(t0));
581
710
  requestFailed(0);
582
711
  });
583
712
  }
@@ -585,7 +714,7 @@
585
714
  return p;
586
715
  };
587
716
  }
588
- if ((TRAIL.request || NUDGE.requests) && window.XMLHttpRequest) {
717
+ if ((TRAIL.request || NUDGE.requests || NUDGE.stalled || NUDGE.circles) && window.XMLHttpRequest) {
589
718
  var XP = XMLHttpRequest.prototype, xopen = XP.open, xsend = XP.send;
590
719
  XP.open = function (m, u) {
591
720
  try { this.__heresay = { m: String(m || 'GET').toUpperCase(), u: String(u) }; } catch (e) { /* ignore */ }
@@ -595,11 +724,12 @@
595
724
  var x = this, r = x.__heresay;
596
725
  try {
597
726
  if (r && !ours(r.u)) {
598
- var aborted = false;
727
+ var aborted = false, t0 = Date.now();
599
728
  x.addEventListener('abort', function () { aborted = true; });
600
729
  x.addEventListener('loadend', function () {
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); }
730
+ if (x.status >= 400) { note('request', r.m + ' ' + shortUrl(r.u) + ' → ' + x.status + took(t0)); requestFailed(x.status); }
731
+ else if (x.status === 0 && !aborted) { note('request', r.m + ' ' + shortUrl(r.u) + ' → failed (network error)' + took(t0)); requestFailed(0); }
732
+ else if (x.status) { slow(r.m, r.u, x.status, t0); if (r.m !== 'GET' && r.m !== 'HEAD') sentSomething(); }
603
733
  });
604
734
  }
605
735
  } catch (e) { /* ignore */ }
@@ -639,9 +769,49 @@
639
769
  };
640
770
  });
641
771
  }
772
+ if (TRAIL.error) {
773
+ // Something the page's own security policy blocked: often why a script or an embed is missing.
774
+ document.addEventListener('securitypolicyviolation', function (e) {
775
+ note('error', 'Blocked by the Content Security Policy (' + (e.effectiveDirective || e.violatedDirective) + '): ' +
776
+ (/^https?:/.test(e.blockedURI) ? shortUrl(e.blockedURI) : e.blockedURI || 'inline'));
777
+ });
778
+ // The page stopped answering: a long task of a second or more.
779
+ try {
780
+ new PerformanceObserver(function (l) {
781
+ l.getEntries().forEach(function (t) {
782
+ if (t.duration >= 1000) note('warn', 'The page froze for ' + (Math.round(t.duration / 100) / 10) + ' s');
783
+ });
784
+ }).observe({ type: 'longtask', buffered: true });
785
+ } catch (e) { /* not in this browser */ }
786
+ // What the app told the person: alerts, as screen readers announce them. Checked at most every
787
+ // 300 ms, only when the page changes.
788
+ var shown = typeof WeakMap === 'function' ? new WeakMap() : null, alertTimer = null;
789
+ var checkAlerts = function () {
790
+ alertTimer = null;
791
+ document.querySelectorAll('[role=alert],[role=alertdialog],[aria-live=assertive]').forEach(function (a) {
792
+ if (host.contains(a) || a.closest('[data-heresay-private]')) return;
793
+ var t = (a.getAttribute('aria-label') || a.textContent || '').replace(/\s+/g, ' ').trim();
794
+ if (shown.get(a) === t) return;
795
+ shown.set(a, t);
796
+ if (t) note('warn', 'The app showed: "' + (t.length > 120 ? t.slice(0, 119) + '…' : t) + '"');
797
+ });
798
+ };
799
+ if (shown && window.MutationObserver) {
800
+ new MutationObserver(function () { if (!alertTimer) alertTimer = setTimeout(checkAlerts, 300); })
801
+ .observe(document.documentElement, { childList: true, subtree: true, characterData: true });
802
+ }
803
+ }
642
804
  if (TRAIL.state) {
643
805
  window.addEventListener('offline', function () { note('state', 'Went offline'); });
644
806
  window.addEventListener('online', function () { note('state', 'Back online'); });
807
+ // Leaving the tab and coming back: a session can expire, a socket drop, while they are away.
808
+ var hiddenAt = 0;
809
+ document.addEventListener('visibilitychange', function () {
810
+ if (document.visibilityState === 'hidden') { hiddenAt = Date.now(); return; }
811
+ var s = hiddenAt ? Math.round((Date.now() - hiddenAt) / 1000) : 0;
812
+ hiddenAt = 0;
813
+ 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'));
814
+ });
645
815
  }
646
816
 
647
817
  // ---- offering help ---------------------------------------------------------------------
@@ -655,6 +825,15 @@
655
825
  * errors an uncaught error or failed promise within 5 s of a click
656
826
  * requests 2 requests failing (5xx or no answer) within 30 s, while online
657
827
  *
828
+ * And when someone seems unsure rather than blocked ("Stuck on something?", opening as Confusing):
829
+ *
830
+ * stalled typed in a field, then 45 s with no more typing and nothing sent, while still
831
+ * on the page and moving or scrolling (not away). Search boxes don't count.
832
+ * circles 6 page changes in a minute among at most 3 pages, one of them seen 3 times,
833
+ * with nothing sent
834
+ * refused the same field refused 3 times in 2 minutes (the browser's check, or the app
835
+ * setting aria-invalid)
836
+ *
658
837
  * At most once per tab, and not for 7 days after "Not now".
659
838
  */
660
839
  var DEAD_WAIT = 1500, DEAD_SPAN = 10000, DEAD_COUNT = 3;
@@ -729,7 +908,70 @@
729
908
  fails = fails.filter(function (t) { return now - t < 30000; }).concat(now);
730
909
  if (fails.length >= 2) { fails = []; trouble('requests'); }
731
910
  }
732
- function trouble(why) { if (NUDGE[why]) offerHelp(); }
911
+ function trouble(why) { if (NUDGE[why]) offerHelp(/^(stalled|circles|refused)$/.test(why) ? 'stuck' : 'broken'); }
912
+
913
+ // Unsure, not blocked. Anything sent (a form, a request that changes something) means they
914
+ // got there, so it starts these over.
915
+ var sentAt = 0;
916
+ function sentSomething() { sentAt = Date.now(); visits = []; typedAt = 0; }
917
+ document.addEventListener('submit', function (e) { if (!host.contains(e.target)) sentSomething(); }, true);
918
+
919
+ // Going in circles: a few pages, over and over, inside a minute.
920
+ function visited(where) {
921
+ if (!NUDGE.circles) return;
922
+ var now = Date.now();
923
+ visits = visits.filter(function (v) { return now - v.at < 60000; }).concat({ at: now, where: where });
924
+ if (visits.length < 6) return;
925
+ var count = {};
926
+ visits.forEach(function (v) { count[v.where] = (count[v.where] || 0) + 1; });
927
+ var pages = Object.keys(count);
928
+ if (pages.length <= 3 && pages.some(function (k) { return count[k] >= 3; })) { visits = []; trouble('circles'); }
929
+ }
930
+
931
+ // Typing that stopped: 45 s after the last keystroke, still here (moved or scrolled in the last
932
+ // 15 s), on the same page, and nothing sent.
933
+ var typedWhere = null, hereAt = 0, stallTimer = null;
934
+ var SEARCH = 'input[type=search],[role=search] input,[role=searchbox],[role=combobox]';
935
+ if (NUDGE.stalled) {
936
+ document.addEventListener('input', function (e) {
937
+ var t = e.target;
938
+ if (!t || !t.closest || host.contains(t) || t === host) return;
939
+ if (!/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName) && !t.isContentEditable) return;
940
+ if (t.matches(SEARCH) || /search/i.test((t.name || '') + ' ' + (t.id || '') + ' ' + (t.getAttribute('placeholder') || ''))) return;
941
+ typedAt = Date.now();
942
+ typedWhere = location.pathname + location.hash;
943
+ if (!stallTimer) stallTimer = setInterval(checkStall, 5000);
944
+ }, true);
945
+ ['pointermove', 'scroll', 'wheel', 'touchmove'].forEach(function (ev) {
946
+ window.addEventListener(ev, function () { hereAt = Date.now(); }, { passive: true, capture: true });
947
+ });
948
+ }
949
+ function checkStall() {
950
+ var now = Date.now();
951
+ if (!typedAt || typedWhere !== location.pathname + location.hash) { clearInterval(stallTimer); stallTimer = null; typedAt = 0; return; }
952
+ if (now - typedAt < 45000 || now - hereAt > 15000 || document.visibilityState === 'hidden') return;
953
+ clearInterval(stallTimer); stallTimer = null; typedAt = 0;
954
+ trouble('stalled');
955
+ }
956
+
957
+ // The same field refused again and again: the browser's own check, or the app marking it
958
+ // aria-invalid.
959
+ var refusals = typeof WeakMap === 'function' ? new WeakMap() : null;
960
+ function refused(t) {
961
+ if (!NUDGE.refused || !refusals || !t || host.contains(t)) return;
962
+ var now = Date.now();
963
+ var r = (refusals.get(t) || []).filter(function (at) { return now - at < 120000; }).concat(now);
964
+ refusals.set(t, r);
965
+ if (r.length >= 3) { refusals.set(t, []); trouble('refused'); }
966
+ }
967
+ if (NUDGE.refused) {
968
+ document.addEventListener('invalid', function (e) { refused(e.target); }, true);
969
+ if (window.MutationObserver) {
970
+ new MutationObserver(function (ms) {
971
+ ms.forEach(function (m) { if (m.target.getAttribute && m.target.getAttribute('aria-invalid') === 'true') refused(m.target); });
972
+ }).observe(document.documentElement, { subtree: true, attributes: true, attributeFilter: ['aria-invalid'] });
973
+ }
974
+ }
733
975
 
734
976
  // ---- network ---------------------------------------------------------------------------
735
977
 
@@ -1161,7 +1403,10 @@
1161
1403
  }));
1162
1404
  box.appendChild(el('label', { class: 'switch' }, [on, el('span', { text: S.attachTrail })]));
1163
1405
  box.appendChild(el('div', { class: 'chips' }, chips));
1164
- box.appendChild(el('details', {}, [el('summary', { text: S.seeTrail }), el('p', { class: 'small', text: S.trailHint }), list]));
1406
+ var c = context();
1407
+ var device = [c.device, c.screen, c.theme, c.locale, c.timezone, c.network, c.settings].filter(Boolean).join(' · ');
1408
+ box.appendChild(el('details', {}, [el('summary', { text: S.seeTrail }), el('p', { class: 'small', text: S.trailHint }), list,
1409
+ device ? el('p', { class: 'small', text: S.alsoSent + device }) : null]));
1165
1410
  return box;
1166
1411
  }
1167
1412
 
@@ -1303,7 +1548,9 @@
1303
1548
  }
1304
1549
  return false;
1305
1550
  }
1306
- function offerHelp() {
1551
+ /** `kind`: 'broken' (something failed; opens as Broken) or 'stuck' (they seem unsure; Confusing). */
1552
+ function offerHelp(kind) {
1553
+ var stuck = kind === 'stuck';
1307
1554
  if (dead || scrim || bubble || nudgeEl || !host.isConnected || hiddenHere() || document.visibilityState === 'hidden') return false;
1308
1555
  if (Date.now() - (+load(NUDGE_NO) || 0) < NUDGE_REST) return false;
1309
1556
  if (offeredInTab()) return false;
@@ -1321,13 +1568,14 @@
1321
1568
  onpointerenter: stay, onpointerleave: later, onfocusin: stay, onfocusout: later,
1322
1569
  onkeydown: function (e) { if (e.key === 'Escape') done(true); },
1323
1570
  }, [
1324
- el('b', { text: S.nudgeTitle }),
1325
- el('p', { text: S.nudgeBody }),
1571
+ el('b', { text: stuck ? S.nudgeStuckTitle : S.nudgeTitle }),
1572
+ el('p', { text: stuck ? S.nudgeStuckBody : S.nudgeBody }),
1326
1573
  el('div', { class: 'row' }, [
1327
1574
  el('button', { class: 'link', type: 'button', text: S.nudgeNo, onclick: function () { done(true); } }),
1328
1575
  el('button', { class: 'send', type: 'button', text: S.nudgeYes, onclick: function () {
1329
1576
  done(false);
1330
- if (!state.type && OFFERED.some(function (t) { return t.id === 'broken'; })) state.type = 'broken';
1577
+ var as = stuck ? 'confusing' : 'broken';
1578
+ if (!state.type && OFFERED.some(function (t) { return t.id === as; })) state.type = as;
1331
1579
  open('new');
1332
1580
  } }),
1333
1581
  ]),
@@ -1340,6 +1588,7 @@
1340
1588
 
1341
1589
  function mount() {
1342
1590
  if (dead) return;
1591
+ versionSeen(state.version);
1343
1592
  if (!host.isConnected) document.body.appendChild(host);
1344
1593
  placeFab();
1345
1594
  refresh();
@@ -1356,10 +1605,10 @@
1356
1605
  state.userEmail = u.email != null ? String(u.email) : null;
1357
1606
  if (scrim && view === 'prefs') renderPanel();
1358
1607
  },
1359
- setVersion: function (v) { state.version = v != null ? String(v) : null; },
1608
+ setVersion: function (v) { state.version = v != null ? String(v) : null; versionSeen(state.version); },
1360
1609
  setScreen: function (s) {
1361
1610
  state.screen = s != null ? String(s) : null;
1362
- if (state.screen) note('page', state.screen);
1611
+ if (state.screen) { note('page', state.screen); visited('screen:' + state.screen); }
1363
1612
  },
1364
1613
  /** Open the report form. { type, text } fill it in; the reporter still reviews and sends. */
1365
1614
  open: function (o) {
@@ -1372,8 +1621,9 @@
1372
1621
  /** Show the one-time introduction now. False if it was already shown on this device. */
1373
1622
  introduce: function (o) { return introduce(o); },
1374
1623
  /** The app saw trouble itself (an error screen, a retry that failed): offer to report it.
1624
+ * { stuck: true } for someone who seems unsure ("Stuck on something?", opens as Confusing).
1375
1625
  * Works without data-nudge; the same limits apply. False if it did not show. */
1376
- nudge: function () { return offerHelp(); },
1626
+ nudge: function (o) { return offerHelp(o && o.stuck ? 'stuck' : 'broken'); },
1377
1627
  /** on('sent', fn): fn({ id, type }) after each report is sent. Returns a function that stops it. */
1378
1628
  on: function (event, fn) {
1379
1629
  if (event !== 'sent' || typeof fn !== 'function') return function () {};