Skip to content

Commit

Permalink
A more solid error handling. (#4079)
Browse files Browse the repository at this point in the history
  • Loading branch information
soulgalore committed Feb 11, 2024
1 parent 608482f commit c7e4f0a
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 124 deletions.
88 changes: 46 additions & 42 deletions lib/plugins/browsertime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,51 +498,55 @@ export default class BrowsertimePlugin extends SitespeedioPlugin {

// If the coach is turned on, collect the coach result
if (options.coach) {
const coachAdvice = browserScriptsData.coach.coachAdvice;
// check if the coach has error(s)
if (!isEmpty(coachAdvice.errors)) {
log.error(
'%s generated the following errors in the coach %:2j',
url,
coachAdvice.errors
);
super.sendMessage(
'error',
'The coach got the following errors: ' +
JSON.stringify(coachAdvice.errors),
{
try {
const coachAdvice = browserScriptsData.coach.coachAdvice;
// check if the coach has error(s)
if (!isEmpty(coachAdvice.errors)) {
log.error(
'%s generated the following errors in the coach %:2j',
url,
runIndex,
iteration: runIndex + 1
}
);
}
coachAdvice.errors
);
super.sendMessage(
'error',
'The coach got the following errors: ' +
JSON.stringify(coachAdvice.errors),
{
url,
runIndex,
iteration: runIndex + 1
}
);
}

let advice = coachAdvice;
// If we run without HAR
if (result.har) {
// make sure to get the right run in the HAR
const myHar = pickAPage(result.har, harIndex);

const harResult = await analyseHar(
myHar,
undefined,
coachAdvice,
options
);
advice = merge(coachAdvice, harResult);
}
const thirdPartyWebVersion = getThirdPartyWebVersion();
const wappalyzerVersion = getWappalyzerCoreVersion();
advice.thirdPartyWebVersion = thirdPartyWebVersion;
advice.wappalyzerVersion = wappalyzerVersion;
let advice = coachAdvice;
// If we run without HAR
if (result.har) {
// make sure to get the right run in the HAR
const myHar = pickAPage(result.har, harIndex);

const harResult = await analyseHar(
myHar,
undefined,
coachAdvice,
options
);
advice = merge(coachAdvice, harResult);
}
const thirdPartyWebVersion = getThirdPartyWebVersion();
const wappalyzerVersion = getWappalyzerCoreVersion();
advice.thirdPartyWebVersion = thirdPartyWebVersion;
advice.wappalyzerVersion = wappalyzerVersion;

super.sendMessage('coach.run', advice, {
url,
group,
runIndex,
iteration: runIndex + 1
});
super.sendMessage('coach.run', advice, {
url,
group,
runIndex,
iteration: runIndex + 1
});
} catch (error) {
log.error('Could not generate coach data', error);
}
}

this.browsertimeAggregator.addToAggregate(run, group);
Expand Down
165 changes: 83 additions & 82 deletions lib/plugins/html/templates/url/thirdparty/index.pug
Original file line number Diff line number Diff line change
@@ -1,92 +1,93 @@
include ../../_tableMixins

- const pagexray = pageInfo.data.pagexray.run || pageInfo.data.pagexray.pageSummary;
- const thirdparty = medianRun ? pageInfo.data.thirdparty.pageSummary.runs[medianRun.runIndex - 1] : pageInfo.data.thirdparty.run;
if pageInfo.data.coach
- const pagexray = pageInfo.data.pagexray.run || pageInfo.data.pagexray.pageSummary;
- const thirdparty = medianRun ? pageInfo.data.thirdparty.pageSummary.runs[medianRun.runIndex - 1] : pageInfo.data.thirdparty.run;

small
||
if thirdparty.category && Object.keys(thirdparty.category).length > 0
a(href='#third-party-categories') Categories |
|  | 
if thirdparty.assets && Object.keys(thirdparty.assets).length > 0
a(href='#third-party-tools') Tools |
|  | 
if pagexray.cookieNamesThirdParties.length > 0
a(href='#third-party-cookies') Cookies |
|  | 
if pagexray.firstParty.requests || options.firstParty
a(href='#first-vs-third') First vs third
|  | 
a#third-party
a#third-party-categories
h2 Third party
small
||
if thirdparty.category && Object.keys(thirdparty.category).length > 0
a(href='#third-party-categories') Categories |
|  | 
if thirdparty.assets && Object.keys(thirdparty.assets).length > 0
a(href='#third-party-tools') Tools |
|  | 
if pagexray.cookieNamesThirdParties.length > 0
a(href='#third-party-cookies') Cookies |
|  | 
if pagexray.firstParty.requests || options.firstParty
a(href='#first-vs-third') First vs third
|  | 
a#third-party
a#third-party-categories
h2 Third party

- const thirdPartyWebVersion = pageInfo.data.coach.run ? pageInfo.data.coach.run.thirdPartyWebVersion : pageInfo.data.coach.pageSummary.thirdPartyWebVersion;
p Third party requests categorised by
a(href='https://github.com/patrickhulce/third-party-web') Third party web
|  version #{thirdPartyWebVersion}.
- const thirdPartyWebVersion = pageInfo.data.coach.run ? pageInfo.data.coach.run.thirdPartyWebVersion : pageInfo.data.coach.pageSummary.thirdPartyWebVersion;
p Third party requests categorised by
a(href='https://github.com/patrickhulce/third-party-web') Third party web
|  version #{thirdPartyWebVersion}.

if thirdparty.category && Object.keys(thirdparty.category).length > 0
.row
.one-half.column
table(data-sortable, id='thirdPartyCategories')
+rowHeading(['Category', 'Requests'])
each metric, category in thirdparty.category
if (category !== 'unknown')
tr
td(data-title='Category') #{category}
+numberCell('requests', metric.requests ? metric.requests.median : metric)
.one-half.column
table(data-sortable, id='thirdPartyTools')
+rowHeading(['Category', 'Number of tools'])
each metric, category in thirdparty.category
if (category !== 'unknown')
tr
td(data-title='Category') #{category}
+numberCell('Tools', metric.tools ? metric.tools.median :Object.keys(thirdparty.toolsByCategory[category]).length)
if thirdparty.category && Object.keys(thirdparty.category).length > 0
.row
.one-half.column
table(data-sortable, id='thirdPartyCategories')
+rowHeading(['Category', 'Requests'])
each metric, category in thirdparty.category
if (category !== 'unknown')
tr
td(data-title='Category') #{category}
+numberCell('requests', metric.requests ? metric.requests.median : metric)
.one-half.column
table(data-sortable, id='thirdPartyTools')
+rowHeading(['Category', 'Number of tools'])
each metric, category in thirdparty.category
if (category !== 'unknown')
tr
td(data-title='Category') #{category}
+numberCell('Tools', metric.tools ? metric.tools.median :Object.keys(thirdparty.toolsByCategory[category]).length)

if thirdparty.assets && Object.keys(thirdparty.assets).length > 0
a#third-party-tools
h3 Third party requests and tools
button.hidden-small.button.button--primary(onclick='toggleRow(this);') Show/hide third party URLs
table
each category in Object.keys(thirdparty.assets)
tr
td(style='text-transform: uppercase;')
b #{category}
| (#{thirdparty.assets[category].length} requests)
- let oldNames = [];
each asset in thirdparty.assets[category]
if (!oldNames.includes(asset.entity.name))
- oldNames.push(asset.entity.name)
tr
td
if asset.entity.homepage
a(href=asset.entity.homepage) #{asset.entity.name}
else
span #{asset.entity.name}
if thirdparty.assets && Object.keys(thirdparty.assets).length > 0
a#third-party-tools
h3 Third party requests and tools
button.hidden-small.button.button--primary(onclick='toggleRow(this);') Show/hide third party URLs
table
each category in Object.keys(thirdparty.assets)
tr
td(style='text-transform: uppercase;')
b #{category}
| (#{thirdparty.assets[category].length} requests)
- let oldNames = [];
each asset in thirdparty.assets[category]
if (!oldNames.includes(asset.entity.name))
- oldNames.push(asset.entity.name)
tr
td
if asset.entity.homepage
a(href=asset.entity.homepage) #{asset.entity.name}
else
span #{asset.entity.name}

tr.u-hideable
td.url.offendingurl
ul
each asset in thirdparty.assets[category]
li
a(href=asset.url) #{h.shortAsset(asset.url, true)}
b (#{asset.entity.name})
tr.u-hideable
td.url.offendingurl
ul
each asset in thirdparty.assets[category]
li
a(href=asset.url) #{h.shortAsset(asset.url, true)}
b (#{asset.entity.name})

if thirdparty.possibileMissedThirdPartyDomains && thirdparty.possibileMissedThirdPartyDomains.length > 0
h3 Unmatched third party domains
p Here's a list of domains that didn't match any tool in
a(href='https://github.com/patrickhulce/third-party-web') Third party web
| . If you are sure they are third party domains, please do a PR to that project. You can also fine tune the list using
code --firstParty
| .
table
each domain in thirdparty.possibileMissedThirdPartyDomains
tr
td #{domain}
if thirdparty.possibileMissedThirdPartyDomains && thirdparty.possibileMissedThirdPartyDomains.length > 0
h3 Unmatched third party domains
p Here's a list of domains that didn't match any tool in
a(href='https://github.com/patrickhulce/third-party-web') Third party web
| . If you are sure they are third party domains, please do a PR to that project. You can also fine tune the list using
code --firstParty
| .
table
each domain in thirdparty.possibileMissedThirdPartyDomains
tr
td #{domain}

include ./thirdPartyCookies.pug
include ./thirdPartyCookies.pug

if pagexray.firstParty.requests || options.firstParty
include ./firstParty.pug
if pagexray.firstParty.requests || options.firstParty
include ./firstParty.pug

0 comments on commit c7e4f0a

Please sign in to comment.