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
25 changes: 16 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,24 @@ export function harFromMessages(messages, options) {

// Soft navigation events are injected by the caller (e.g. Browsertime)
// when Chrome detects a soft navigation via the PerformanceObserver API.
// Update the current page with the soft navigation URL instead of
// creating a new page, so one measurement = one HAR page.
case 'SoftNavigation.detected': {
{
currentPageId = randomUUID();
const page = {
id: currentPageId,
startedDateTime: '',
title: params.url || '',
pageTimings: {},
_softNavigation: true
};
pages.push(page);
const page = pages.at(-1);
if (page) {
page.title = params.url || '';
page._softNavigation = true;
} else {
currentPageId = randomUUID();
pages.push({
id: currentPageId,
startedDateTime: '',
title: params.url || '',
pageTimings: {},
_softNavigation: true
});
}
}
break;
}
Expand Down
1 change: 1 addition & 0 deletions test/perflogs/soft-navigation-github-code.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/perflogs/soft-navigation-github-issues.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/perflogs/soft-navigation-github-pulls.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/perflogs/soft-navigation-react-back-to-learn.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/perflogs/soft-navigation-react-describing-ui.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/perflogs/soft-navigation-react-first-component.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

69 changes: 61 additions & 8 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,20 +364,73 @@ test('Network.responseReceivedExtraInfo may be fired before or after responseRec
});
});

test('Soft navigation creates a new page', t => {
test('Soft navigation updates the current 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);
// Soft navigation should update the page, not create a new one
t.is(log.pages.length, 1);
t.is(log.pages[0]._softNavigation, true);
t.is(
log.pages[1].title,
log.pages[0].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);
// All entries should belong to the single page
const allOnPage = log.entries.every(e => e.pageref === 'page_1');
t.true(allOnPage);
});
});

test('Multiple GitHub soft navigations each update their page', async t => {
const perflogs = [
[
'soft-navigation-github-pulls.json',
'https://github.com/sitespeedio/browsertime/pulls'
],
[
'soft-navigation-github-code.json',
'https://github.com/sitespeedio/browsertime'
],
[
'soft-navigation-github-issues.json',
'https://github.com/sitespeedio/browsertime/issues'
]
];

for (const [file, expectedUrl] of perflogs) {
const messages = JSON.parse(await fs.readFile(perflog(file), 'utf8'));
const har = harFromMessages(messages);
t.is(har.log.pages.length, 1);
t.is(har.log.pages[0]._softNavigation, true);
t.is(har.log.pages[0].title, expectedUrl);
t.true(har.log.entries.length > 0);
}
});

test('Multiple React soft navigations each update their page', async t => {
const perflogs = [
[
'soft-navigation-react-describing-ui.json',
'https://react.dev/learn/describing-the-ui'
],
[
'soft-navigation-react-first-component.json',
'https://react.dev/learn/your-first-component'
],
[
'soft-navigation-react-importing-exporting.json',
'https://react.dev/learn/importing-and-exporting-components'
],
['soft-navigation-react-back-to-learn.json', 'https://react.dev/learn']
];

for (const [file, expectedUrl] of perflogs) {
const messages = JSON.parse(await fs.readFile(perflog(file), 'utf8'));
const har = harFromMessages(messages);
t.is(har.log.pages.length, 1);
t.is(har.log.pages[0]._softNavigation, true);
t.is(har.log.pages[0].title, expectedUrl);
t.true(har.log.entries.length > 0);
}
});