Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function harFromMessages(messages, options) {

const method = message.method;

if (!/^(Page|Network)\..+/.test(method)) {
if (!/^(Page|Network|SoftNavigation)\..+/.test(method)) {
continue;
}

Expand Down Expand Up @@ -147,6 +147,23 @@ export function harFromMessages(messages, options) {
break;
}

// Soft navigation events are injected by the caller (e.g. Browsertime)
// when Chrome detects a soft navigation via the PerformanceObserver API.
case 'SoftNavigation.detected': {
{
currentPageId = randomUUID();
const page = {
id: currentPageId,
startedDateTime: '',
title: params.url || '',
pageTimings: {},
_softNavigation: true
};
pages.push(page);
}
break;
}

case 'Network.requestWillBeSent': {
{
const request = params.request;
Expand Down
1 change: 1 addition & 0 deletions test/perflogs/soft-navigation-github.json

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,21 @@ test('Network.responseReceivedExtraInfo may be fired before or after responseRec
);
});
});

test('Soft navigation creates a new page', t => {
const perflogPath = perflog('soft-navigation-github.json');
return parsePerflog(perflogPath)
.then(har => har.log)
.then(log => {
// Should have 2 pages: the initial page + the soft navigation
t.is(log.pages.length, 2);
t.is(log.pages[1]._softNavigation, true);
t.is(
log.pages[1].title,
'https://github.com/sitespeedio/browsertime/pulls'
);
// Network requests after the soft navigation should belong to page_2
const softNavEntries = log.entries.filter(e => e.pageref === 'page_2');
t.true(softNavEntries.length > 0);
});
});