Commit 02ac32a1 authored by Andrey Lushnikov's avatar Andrey Lushnikov Committed by Commit Bot

DevTools: introduce Page.navigatedWithinDocument event

This patch introduces a new Page.navigatedWithinDocument event that is
fired whenever a same-document navigation happens.

Same-document navigation might happen due to History API usages or
due to a call to Page.navigate that changes only anchor.

R=dgozman, pfeldman

Change-Id: I1e702606a97f26511806a0d7328490613dc46246
Reviewed-on: https://chromium-review.googlesource.com/999115
Commit-Queue: Andrey Lushnikov <lushnikov@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548690}
parent 90a03402
Tests that Page.navigateWithinDocument is issued for history API and anchor navigation.
-- Test Page.navigate() to anchor URL --
{
method : Page.navigatedWithinDocument
params : {
frameId : <string>
url : http://127.0.0.1:8000/inspector-protocol/resources/inspector-protocol-page.html#foo
}
}
-- Test Page.navigate() to another anchor URL --
{
method : Page.navigatedWithinDocument
params : {
frameId : <string>
url : http://127.0.0.1:8000/inspector-protocol/resources/inspector-protocol-page.html#bar
}
}
-- Test history.pushState() --
{
method : Page.navigatedWithinDocument
params : {
frameId : <string>
url : http://127.0.0.1:8000/inspector-protocol/resources/wow.html
}
}
-- Test history.replaceState() --
{
method : Page.navigatedWithinDocument
params : {
frameId : <string>
url : http://127.0.0.1:8000/replaced.html
}
}
-- Test history.back() --
{
method : Page.navigatedWithinDocument
params : {
frameId : <string>
url : http://127.0.0.1:8000/inspector-protocol/resources/inspector-protocol-page.html#bar
}
}
-- Test history.forward() --
{
method : Page.navigatedWithinDocument
params : {
frameId : <string>
url : http://127.0.0.1:8000/replaced.html
}
}
(async function(testRunner) {
var {page, session, dp} = await testRunner.startBlank(
`Tests that Page.navigateWithinDocument is issued for history API and anchor navigation.`);
await dp.Page.enable();
await dp.Runtime.enable();
testRunner.log('-- Test Page.navigate() to anchor URL --');
await dp.Page.navigate({url: testRunner.url('../resources/inspector-protocol-page.html#foo')});
testRunner.log(await dp.Page.onceNavigatedWithinDocument());
testRunner.log('-- Test Page.navigate() to another anchor URL --');
await dp.Page.navigate({url: testRunner.url('../resources/inspector-protocol-page.html#bar')});
testRunner.log(await dp.Page.onceNavigatedWithinDocument());
testRunner.log('-- Test history.pushState() --');
dp.Runtime.evaluate({ expression: `history.pushState({}, '', 'wow.html')`});
testRunner.log(await dp.Page.onceNavigatedWithinDocument());
testRunner.log('-- Test history.replaceState() --');
dp.Runtime.evaluate({ expression: `history.replaceState({}, '', '/replaced.html')`});
testRunner.log(await dp.Page.onceNavigatedWithinDocument());
testRunner.log('-- Test history.back() --');
dp.Runtime.evaluate({ expression: `history.back()`});
testRunner.log(await dp.Page.onceNavigatedWithinDocument());
testRunner.log('-- Test history.forward() --');
dp.Runtime.evaluate({ expression: `history.forward()`});
testRunner.log(await dp.Page.onceNavigatedWithinDocument());
testRunner.completeTest();
})
......@@ -775,6 +775,14 @@ Response InspectorPageAgent::setDocumentContent(const String& frame_id,
return Response::OK();
}
void InspectorPageAgent::DidNavigateWithinDocument(LocalFrame* frame) {
Document* document = frame->GetDocument();
if (document) {
return GetFrontend()->navigatedWithinDocument(
IdentifiersFactory::FrameId(frame), document->Url());
}
}
void InspectorPageAgent::DidClearDocumentOfWindowObject(LocalFrame* frame) {
if (!GetFrontend())
return;
......
......@@ -154,6 +154,7 @@ class CORE_EXPORT InspectorPageAgent final
// InspectorInstrumentation API
void DidClearDocumentOfWindowObject(LocalFrame*);
void DidNavigateWithinDocument(LocalFrame*);
void DomContentLoadedEventFired(LocalFrame*);
void LoadEventFired(LocalFrame*);
void WillCommitLoad(LocalFrame*, DocumentLoader*);
......
......@@ -10884,6 +10884,23 @@
}
]
},
{
"name": "navigatedWithinDocument",
"description": "Fired when same-document navigation happens, e.g. due to history API usage or anchor navigation.",
"experimental": true,
"parameters": [
{
"name": "frameId",
"description": "Id of the frame.",
"$ref": "FrameId"
},
{
"name": "url",
"description": "Frame's new url.",
"type": "string"
}
]
},
{
"name": "screencastFrame",
"description": "Compressed image data requested by the `startScreencast`.",
......
......@@ -4999,6 +4999,14 @@ domain Page
parameters
Network.MonotonicTime timestamp
# Fired when same-document navigation happens, e.g. due to history API usage or anchor navigation.
experimental event navigatedWithinDocument
parameters
# Id of the frame.
FrameId frameId
# Frame's new url.
string url
# Compressed image data requested by the `startScreencast`.
experimental event screencastFrame
parameters
......
......@@ -338,6 +338,7 @@ void DocumentLoader::UpdateForSameDocumentNavigation(
frame_->IsLocalRoot());
GetLocalFrameClient().DispatchDidNavigateWithinPage(
history_item_.Get(), commit_type, initiating_document);
probe::didNavigateWithinDocument(frame_);
}
const KURL& DocumentLoader::UrlForHistory() const {
......
......@@ -146,6 +146,7 @@
probes: [
"didChangeViewport",
"didClearDocumentOfWindowObject",
"didNavigateWithinDocument",
"willCommitLoad",
"didResizeMainFrame",
"didRunJavaScriptDialog",
......
......@@ -123,6 +123,7 @@ interface CoreProbes {
void frameDetachedFromParent([Keep] LocalFrame*);
void willCommitLoad([Keep] LocalFrame*, DocumentLoader*);
void didCommitLoad([Keep] LocalFrame*, DocumentLoader*);
void didNavigateWithinDocument([Keep] LocalFrame*);
void frameDocumentUpdated([Keep] LocalFrame*);
void frameOwnerContentUpdated([Keep] LocalFrame*, HTMLFrameOwnerElement*);
void frameStartedLoading([Keep] LocalFrame*, FrameLoadType);
......
......@@ -865,6 +865,14 @@ SDK.PageDispatcher = class {
frameClearedScheduledNavigation(frameId) {
}
/**
* @override
* @param {!Protocol.Page.FrameId} frameId
* @param {string} url
*/
navigatedWithinDocument(frameId, url) {
}
/**
* @override
*/
......
......@@ -111,6 +111,14 @@ SDK.ScreenCaptureModel = class extends SDK.SDKModel {
lifecycleEvent(frameId, loaderId, name, time) {
}
/**
* @override
* @param {!Protocol.Page.FrameId} frameId
* @param {string} url
*/
navigatedWithinDocument(frameId, url) {
}
/**
* @override
* @param {!Protocol.Page.FrameId} frameId
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment