haikuwebkit/LayoutTests/inspector/page/setBootstrapScript-main-fra...

42 lines
1.6 KiB
HTML
Raw Permalink Normal View History

Web Inspector: provide a way to inject "bootstrap" JavaScript into the page as the first script executed https://bugs.webkit.org/show_bug.cgi?id=195847 <rdar://problem/48950551> Reviewed by Joseph Pecoraro. Source/JavaScriptCore: When debugging webpages, it's often useful to be able to swizzle various functions in order to add extra logs for when they're called (e.g. `Event.prototype.preventDefault`). Sometimes this can be difficult, such as if the page saves a copy of the function and references that instead, in which case it would be helpful to have a way to guarantee that the swizzled code is the first thing evaluated after the context is created. This change adds support for that concept, which has been named Inspector Bootstrap Script. Once created, it will be injected as the first user script to every new global object that is created afterwards. Modifications to the Inspector Bootstrap Script take effect for all new global objects created _after_ the modification happened. * inspector/protocol/Page.json: Add `setBoostrapScript` command. Source/WebCore: When debugging webpages, it's often useful to be able to swizzle various functions in order to add extra logs for when they're called (e.g. `Event.prototype.preventDefault`). Sometimes this can be difficult, such as if the page saves a copy of the function and references that instead, in which case it would be helpful to have a way to guarantee that the swizzled code is the first thing evaluated after the context is created. This change adds support for that concept, which has been named Inspector Bootstrap Script. Once created, it will be injected as the first user script to every new global object that is created afterwards. Modifications to the Inspector Bootstrap Script take effect for all new global objects created _after_ the modification happened. Tests: inspector/page/setBootstrapScript-main-frame.html inspector/page/setBootstrapScript-sub-frame.html * inspector/agents/InspectorPageAgent.h: * inspector/agents/InspectorPageAgent.cpp: (WebCore::InspectorPageAgent::setBootstrapScript): Added. (WebCore::InspectorPageAgent::didClearWindowObjectInWorld): Added. * inspector/InspectorInstrumentation.cpp: (WebCore::InspectorInstrumentation::didClearWindowObjectInWorldImpl): * inspector/agents/page/PageDebuggerAgent.h: * inspector/agents/page/PageDebuggerAgent.cpp: (WebCore::PageDebuggerAgent::didClearWindowObjectInWorld): Added. (WebCore::PageDebuggerAgent::didClearMainFrameWindowObject): Deleted. * inspector/agents/page/PageRuntimeAgent.h: * inspector/agents/page/PageRuntimeAgent.cpp: (WebCore::PageRuntimeAgent::didClearWindowObjectInWorld): Added. (WebCore::PageRuntimeAgent::didCreateMainWorldContext): Deleted. Rename existing global object creation "notifications" for more consistency between agents. Source/WebInspectorUI: When debugging webpages, it's often useful to be able to swizzle various functions in order to add extra logs for when they're called (e.g. `Event.prototype.preventDefault`). Sometimes this can be difficult, such as if the page saves a copy of the function and references that instead, in which case it would be helpful to have a way to guarantee that the swizzled code is the first thing evaluated after the context is created. This change adds support for that concept, which has been named Inspector Bootstrap Script. Once created, it will be injected as the first user script to every new global object that is created afterwards. Modifications to the Inspector Bootstrap Script take effect for all new global objects created _after_ the modification happened. * UserInterface/Controllers/NetworkManager.js: (WI.NetworkManager): (WI.NetworkManager.supportsBootstrapScript): Added. (WI.NetworkManager.get bootstrapScriptURL): Added. (WI.NetworkManager.get bootstrapScriptSourceObjectStoreKey): Added. (WI.NetworkManager.prototype.initializeTarget): (WI.NetworkManager.prototype.get bootstrapScript): Added. (WI.NetworkManager.prototype.get bootstrapScriptEnabled): Added. (WI.NetworkManager.prototype.set bootstrapScriptEnabled): Added. (WI.NetworkManager.prototype.async createBootstrapScript): Added. (WI.NetworkManager.prototype.destroyBootstrapScript): Added. (WI.NetworkManager.prototype._processServiceWorkerConfiguration): (WI.NetworkManager.prototype._handleBootstrapScriptContentDidChange): Added. * UserInterface/Models/LocalScript.js: (WI.LocalScript): (WI.LocalScript.prototype.get editable): Added. (WI.LocalScript.prototype.get supportsScriptBlackboxing): Added. (WI.LocalScript.prototype.requestContentFromBackend): (WI.LocalScript.prototype.handleCurrentRevisionContentChange): Added. * UserInterface/Views/ScriptContentView.js: (WI.ScriptContentView): (WI.ScriptContentView.prototype._contentWillPopulate): (WI.ScriptContentView.prototype._contentDidPopulate): (WI.ScriptContentView.prototype._handleTextEditorContentDidChange): Added. Support editing of `WI.LocalScript` that are specifically marked as such. * UserInterface/Models/Script.js: (WI.Script): (WI.Script.prototype.get displayName): (WI.Script.prototype.get displayURL): (WI.Script.prototype.isMainResource): (WI.Script.prototype._resolveResource): * UserInterface/Views/SourceCodeTextEditor.js: (WI.SourceCodeTextEditor.prototype.customPerformSearch): (WI.SourceCodeTextEditor.prototype._createTypeTokenAnnotator): (WI.SourceCodeTextEditor.prototype._createBasicBlockAnnotator): Allow a `WI.Script` to not have an associated `WI.Target`, specifically for `WI.LocalScript`. * UserInterface/Views/SourcesNavigationSidebarPanel.js: (WI.SourcesNavigationSidebarPanel): (WI.SourcesNavigationSidebarPanel.prototype.treeElementForRepresentedObject): (WI.SourcesNavigationSidebarPanel.prototype.createContentTreeOutline): (WI.SourcesNavigationSidebarPanel.prototype._compareTreeElements): (WI.SourcesNavigationSidebarPanel.prototype._addLocalOverride): Added. (WI.SourcesNavigationSidebarPanel.prototype._removeResourceOverride): Added. (WI.SourcesNavigationSidebarPanel.prototype._populateCreateResourceContextMenu): (WI.SourcesNavigationSidebarPanel.prototype._handleBootstrapScriptCreated): Added. (WI.SourcesNavigationSidebarPanel.prototype._handleBootstrapScriptDestroyed): Added. (WI.SourcesNavigationSidebarPanel.prototype._handleLocalResourceOverrideAdded): (WI.SourcesNavigationSidebarPanel.prototype._handleLocalResourceOverrideRemoved): (WI.SourcesNavigationSidebarPanel.prototype._handleDebuggerPaused): (WI.SourcesNavigationSidebarPanel.prototype._handleDebuggerResumed): (WI.SourcesNavigationSidebarPanel.prototype._addLocalResourceOverride): Removed. (WI.SourcesNavigationSidebarPanel.prototype._removeLocalResourceOverride): Removed. Add an item in the create resource context menu for creating/focusing the bootstrap script. * UserInterface/Views/ScriptTreeElement.js: (WI.ScriptTreeElement): * UserInterface/Views/BootstrapScriptTreeElement.js: Added. (WI.BootstrapScriptTreeElement): (WI.BootstrapScriptTreeElement.prototype.onattach): (WI.BootstrapScriptTreeElement.prototype.ondetach): (WI.BootstrapScriptTreeElement.prototype.ondelete): (WI.BootstrapScriptTreeElement.prototype.onspace): (WI.BootstrapScriptTreeElement.prototype.canSelectOnMouseDown): (WI.BootstrapScriptTreeElement.prototype.populateContextMenu): (WI.BootstrapScriptTreeElement.prototype.updateStatus): (WI.BootstrapScriptTreeElement.prototype._handleNetworkManagerBootstrapScriptToggled): * UserInterface/Views/BootstrapScriptTreeElement.css: Added. (.item.script.bootstrap .status > input[type="checkbox"]): * UserInterface/Views/LocalResourceOverrideTreeElement.css: (.item.resource.override .status > input[type="checkbox"]): Added. (.item.resource.override .status > div): Removed. Don't show the full bootstrap script URL. Instead, show "Inspector Bootstrap Script". * UserInterface/Views/OpenResourceDialog.js: (WI.OpenResourceDialog.prototype.didPresentDialog): Show the bootstrap script in the open resource dialog. * UserInterface/Base/Utilities.js: (isWebInspectorBootstrapScript): Added. * UserInterface/Controllers/DebuggerManager.js: (WI.DebuggerManager.prototype.scriptDidFail): * UserInterface/Base/ObjectStore.js: (WI.ObjectStore.static _open): (WI.ObjectStore.prototype.async get): Added. Add a generalized object store that can be used for one-off values that need the larger storage capacity of `IndexedDB`. * .eslintrc: * Localizations/en.lproj/localizedStrings.js: LayoutTests: * inspector/page/setBootstrapScript-main-frame.html: Added. * inspector/page/setBootstrapScript-main-frame-expected.txt: Added. * inspector/page/setBootstrapScript-sub-frame.html: Added. * inspector/page/setBootstrapScript-sub-frame-expected.txt: Added. * inspector/page/resources/bootstrap-iframe.html: Added. Canonical link: https://commits.webkit.org/216764@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@251531 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-10-24 06:54:49 +00:00
<!DOCTYPE html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script>
function test()
{
let suite = InspectorTest.createAsyncSuite("Page.setBootstrapScript");
suite.addTestCase({
name: "Page.setBootstrapScript.MainFrame",
description: "Test that the bootstrap script is executed in the main frame.",
async test() {
InspectorTest.assert(!WI.networkManager.bootstrapScript, "Should not already have a bootstrap script.");
Web Inspector: provide a way to inject "bootstrap" JavaScript into the page as the first script executed https://bugs.webkit.org/show_bug.cgi?id=195847 <rdar://problem/48950551> Reviewed by Joseph Pecoraro. Source/JavaScriptCore: When debugging webpages, it's often useful to be able to swizzle various functions in order to add extra logs for when they're called (e.g. `Event.prototype.preventDefault`). Sometimes this can be difficult, such as if the page saves a copy of the function and references that instead, in which case it would be helpful to have a way to guarantee that the swizzled code is the first thing evaluated after the context is created. This change adds support for that concept, which has been named Inspector Bootstrap Script. Once created, it will be injected as the first user script to every new global object that is created afterwards. Modifications to the Inspector Bootstrap Script take effect for all new global objects created _after_ the modification happened. * inspector/protocol/Page.json: Add `setBoostrapScript` command. Source/WebCore: When debugging webpages, it's often useful to be able to swizzle various functions in order to add extra logs for when they're called (e.g. `Event.prototype.preventDefault`). Sometimes this can be difficult, such as if the page saves a copy of the function and references that instead, in which case it would be helpful to have a way to guarantee that the swizzled code is the first thing evaluated after the context is created. This change adds support for that concept, which has been named Inspector Bootstrap Script. Once created, it will be injected as the first user script to every new global object that is created afterwards. Modifications to the Inspector Bootstrap Script take effect for all new global objects created _after_ the modification happened. Tests: inspector/page/setBootstrapScript-main-frame.html inspector/page/setBootstrapScript-sub-frame.html * inspector/agents/InspectorPageAgent.h: * inspector/agents/InspectorPageAgent.cpp: (WebCore::InspectorPageAgent::setBootstrapScript): Added. (WebCore::InspectorPageAgent::didClearWindowObjectInWorld): Added. * inspector/InspectorInstrumentation.cpp: (WebCore::InspectorInstrumentation::didClearWindowObjectInWorldImpl): * inspector/agents/page/PageDebuggerAgent.h: * inspector/agents/page/PageDebuggerAgent.cpp: (WebCore::PageDebuggerAgent::didClearWindowObjectInWorld): Added. (WebCore::PageDebuggerAgent::didClearMainFrameWindowObject): Deleted. * inspector/agents/page/PageRuntimeAgent.h: * inspector/agents/page/PageRuntimeAgent.cpp: (WebCore::PageRuntimeAgent::didClearWindowObjectInWorld): Added. (WebCore::PageRuntimeAgent::didCreateMainWorldContext): Deleted. Rename existing global object creation "notifications" for more consistency between agents. Source/WebInspectorUI: When debugging webpages, it's often useful to be able to swizzle various functions in order to add extra logs for when they're called (e.g. `Event.prototype.preventDefault`). Sometimes this can be difficult, such as if the page saves a copy of the function and references that instead, in which case it would be helpful to have a way to guarantee that the swizzled code is the first thing evaluated after the context is created. This change adds support for that concept, which has been named Inspector Bootstrap Script. Once created, it will be injected as the first user script to every new global object that is created afterwards. Modifications to the Inspector Bootstrap Script take effect for all new global objects created _after_ the modification happened. * UserInterface/Controllers/NetworkManager.js: (WI.NetworkManager): (WI.NetworkManager.supportsBootstrapScript): Added. (WI.NetworkManager.get bootstrapScriptURL): Added. (WI.NetworkManager.get bootstrapScriptSourceObjectStoreKey): Added. (WI.NetworkManager.prototype.initializeTarget): (WI.NetworkManager.prototype.get bootstrapScript): Added. (WI.NetworkManager.prototype.get bootstrapScriptEnabled): Added. (WI.NetworkManager.prototype.set bootstrapScriptEnabled): Added. (WI.NetworkManager.prototype.async createBootstrapScript): Added. (WI.NetworkManager.prototype.destroyBootstrapScript): Added. (WI.NetworkManager.prototype._processServiceWorkerConfiguration): (WI.NetworkManager.prototype._handleBootstrapScriptContentDidChange): Added. * UserInterface/Models/LocalScript.js: (WI.LocalScript): (WI.LocalScript.prototype.get editable): Added. (WI.LocalScript.prototype.get supportsScriptBlackboxing): Added. (WI.LocalScript.prototype.requestContentFromBackend): (WI.LocalScript.prototype.handleCurrentRevisionContentChange): Added. * UserInterface/Views/ScriptContentView.js: (WI.ScriptContentView): (WI.ScriptContentView.prototype._contentWillPopulate): (WI.ScriptContentView.prototype._contentDidPopulate): (WI.ScriptContentView.prototype._handleTextEditorContentDidChange): Added. Support editing of `WI.LocalScript` that are specifically marked as such. * UserInterface/Models/Script.js: (WI.Script): (WI.Script.prototype.get displayName): (WI.Script.prototype.get displayURL): (WI.Script.prototype.isMainResource): (WI.Script.prototype._resolveResource): * UserInterface/Views/SourceCodeTextEditor.js: (WI.SourceCodeTextEditor.prototype.customPerformSearch): (WI.SourceCodeTextEditor.prototype._createTypeTokenAnnotator): (WI.SourceCodeTextEditor.prototype._createBasicBlockAnnotator): Allow a `WI.Script` to not have an associated `WI.Target`, specifically for `WI.LocalScript`. * UserInterface/Views/SourcesNavigationSidebarPanel.js: (WI.SourcesNavigationSidebarPanel): (WI.SourcesNavigationSidebarPanel.prototype.treeElementForRepresentedObject): (WI.SourcesNavigationSidebarPanel.prototype.createContentTreeOutline): (WI.SourcesNavigationSidebarPanel.prototype._compareTreeElements): (WI.SourcesNavigationSidebarPanel.prototype._addLocalOverride): Added. (WI.SourcesNavigationSidebarPanel.prototype._removeResourceOverride): Added. (WI.SourcesNavigationSidebarPanel.prototype._populateCreateResourceContextMenu): (WI.SourcesNavigationSidebarPanel.prototype._handleBootstrapScriptCreated): Added. (WI.SourcesNavigationSidebarPanel.prototype._handleBootstrapScriptDestroyed): Added. (WI.SourcesNavigationSidebarPanel.prototype._handleLocalResourceOverrideAdded): (WI.SourcesNavigationSidebarPanel.prototype._handleLocalResourceOverrideRemoved): (WI.SourcesNavigationSidebarPanel.prototype._handleDebuggerPaused): (WI.SourcesNavigationSidebarPanel.prototype._handleDebuggerResumed): (WI.SourcesNavigationSidebarPanel.prototype._addLocalResourceOverride): Removed. (WI.SourcesNavigationSidebarPanel.prototype._removeLocalResourceOverride): Removed. Add an item in the create resource context menu for creating/focusing the bootstrap script. * UserInterface/Views/ScriptTreeElement.js: (WI.ScriptTreeElement): * UserInterface/Views/BootstrapScriptTreeElement.js: Added. (WI.BootstrapScriptTreeElement): (WI.BootstrapScriptTreeElement.prototype.onattach): (WI.BootstrapScriptTreeElement.prototype.ondetach): (WI.BootstrapScriptTreeElement.prototype.ondelete): (WI.BootstrapScriptTreeElement.prototype.onspace): (WI.BootstrapScriptTreeElement.prototype.canSelectOnMouseDown): (WI.BootstrapScriptTreeElement.prototype.populateContextMenu): (WI.BootstrapScriptTreeElement.prototype.updateStatus): (WI.BootstrapScriptTreeElement.prototype._handleNetworkManagerBootstrapScriptToggled): * UserInterface/Views/BootstrapScriptTreeElement.css: Added. (.item.script.bootstrap .status > input[type="checkbox"]): * UserInterface/Views/LocalResourceOverrideTreeElement.css: (.item.resource.override .status > input[type="checkbox"]): Added. (.item.resource.override .status > div): Removed. Don't show the full bootstrap script URL. Instead, show "Inspector Bootstrap Script". * UserInterface/Views/OpenResourceDialog.js: (WI.OpenResourceDialog.prototype.didPresentDialog): Show the bootstrap script in the open resource dialog. * UserInterface/Base/Utilities.js: (isWebInspectorBootstrapScript): Added. * UserInterface/Controllers/DebuggerManager.js: (WI.DebuggerManager.prototype.scriptDidFail): * UserInterface/Base/ObjectStore.js: (WI.ObjectStore.static _open): (WI.ObjectStore.prototype.async get): Added. Add a generalized object store that can be used for one-off values that need the larger storage capacity of `IndexedDB`. * .eslintrc: * Localizations/en.lproj/localizedStrings.js: LayoutTests: * inspector/page/setBootstrapScript-main-frame.html: Added. * inspector/page/setBootstrapScript-main-frame-expected.txt: Added. * inspector/page/setBootstrapScript-sub-frame.html: Added. * inspector/page/setBootstrapScript-sub-frame-expected.txt: Added. * inspector/page/resources/bootstrap-iframe.html: Added. Canonical link: https://commits.webkit.org/216764@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@251531 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-10-24 06:54:49 +00:00
let valueBeforeBootstrapScript = await InspectorTest.evaluateInPage(`window.valueFromBootstrapScript`);
InspectorTest.expectEqual(valueBeforeBootstrapScript, undefined, "'valueFromBootstrapScript' should be 'undefined'.");
InspectorTest.log("Setting bootstrap script...");
await WI.networkManager.createBootstrapScript(`window.valueFromBootstrapScript = 42;`);
Web Inspector: provide a way to inject "bootstrap" JavaScript into the page as the first script executed https://bugs.webkit.org/show_bug.cgi?id=195847 <rdar://problem/48950551> Reviewed by Joseph Pecoraro. Source/JavaScriptCore: When debugging webpages, it's often useful to be able to swizzle various functions in order to add extra logs for when they're called (e.g. `Event.prototype.preventDefault`). Sometimes this can be difficult, such as if the page saves a copy of the function and references that instead, in which case it would be helpful to have a way to guarantee that the swizzled code is the first thing evaluated after the context is created. This change adds support for that concept, which has been named Inspector Bootstrap Script. Once created, it will be injected as the first user script to every new global object that is created afterwards. Modifications to the Inspector Bootstrap Script take effect for all new global objects created _after_ the modification happened. * inspector/protocol/Page.json: Add `setBoostrapScript` command. Source/WebCore: When debugging webpages, it's often useful to be able to swizzle various functions in order to add extra logs for when they're called (e.g. `Event.prototype.preventDefault`). Sometimes this can be difficult, such as if the page saves a copy of the function and references that instead, in which case it would be helpful to have a way to guarantee that the swizzled code is the first thing evaluated after the context is created. This change adds support for that concept, which has been named Inspector Bootstrap Script. Once created, it will be injected as the first user script to every new global object that is created afterwards. Modifications to the Inspector Bootstrap Script take effect for all new global objects created _after_ the modification happened. Tests: inspector/page/setBootstrapScript-main-frame.html inspector/page/setBootstrapScript-sub-frame.html * inspector/agents/InspectorPageAgent.h: * inspector/agents/InspectorPageAgent.cpp: (WebCore::InspectorPageAgent::setBootstrapScript): Added. (WebCore::InspectorPageAgent::didClearWindowObjectInWorld): Added. * inspector/InspectorInstrumentation.cpp: (WebCore::InspectorInstrumentation::didClearWindowObjectInWorldImpl): * inspector/agents/page/PageDebuggerAgent.h: * inspector/agents/page/PageDebuggerAgent.cpp: (WebCore::PageDebuggerAgent::didClearWindowObjectInWorld): Added. (WebCore::PageDebuggerAgent::didClearMainFrameWindowObject): Deleted. * inspector/agents/page/PageRuntimeAgent.h: * inspector/agents/page/PageRuntimeAgent.cpp: (WebCore::PageRuntimeAgent::didClearWindowObjectInWorld): Added. (WebCore::PageRuntimeAgent::didCreateMainWorldContext): Deleted. Rename existing global object creation "notifications" for more consistency between agents. Source/WebInspectorUI: When debugging webpages, it's often useful to be able to swizzle various functions in order to add extra logs for when they're called (e.g. `Event.prototype.preventDefault`). Sometimes this can be difficult, such as if the page saves a copy of the function and references that instead, in which case it would be helpful to have a way to guarantee that the swizzled code is the first thing evaluated after the context is created. This change adds support for that concept, which has been named Inspector Bootstrap Script. Once created, it will be injected as the first user script to every new global object that is created afterwards. Modifications to the Inspector Bootstrap Script take effect for all new global objects created _after_ the modification happened. * UserInterface/Controllers/NetworkManager.js: (WI.NetworkManager): (WI.NetworkManager.supportsBootstrapScript): Added. (WI.NetworkManager.get bootstrapScriptURL): Added. (WI.NetworkManager.get bootstrapScriptSourceObjectStoreKey): Added. (WI.NetworkManager.prototype.initializeTarget): (WI.NetworkManager.prototype.get bootstrapScript): Added. (WI.NetworkManager.prototype.get bootstrapScriptEnabled): Added. (WI.NetworkManager.prototype.set bootstrapScriptEnabled): Added. (WI.NetworkManager.prototype.async createBootstrapScript): Added. (WI.NetworkManager.prototype.destroyBootstrapScript): Added. (WI.NetworkManager.prototype._processServiceWorkerConfiguration): (WI.NetworkManager.prototype._handleBootstrapScriptContentDidChange): Added. * UserInterface/Models/LocalScript.js: (WI.LocalScript): (WI.LocalScript.prototype.get editable): Added. (WI.LocalScript.prototype.get supportsScriptBlackboxing): Added. (WI.LocalScript.prototype.requestContentFromBackend): (WI.LocalScript.prototype.handleCurrentRevisionContentChange): Added. * UserInterface/Views/ScriptContentView.js: (WI.ScriptContentView): (WI.ScriptContentView.prototype._contentWillPopulate): (WI.ScriptContentView.prototype._contentDidPopulate): (WI.ScriptContentView.prototype._handleTextEditorContentDidChange): Added. Support editing of `WI.LocalScript` that are specifically marked as such. * UserInterface/Models/Script.js: (WI.Script): (WI.Script.prototype.get displayName): (WI.Script.prototype.get displayURL): (WI.Script.prototype.isMainResource): (WI.Script.prototype._resolveResource): * UserInterface/Views/SourceCodeTextEditor.js: (WI.SourceCodeTextEditor.prototype.customPerformSearch): (WI.SourceCodeTextEditor.prototype._createTypeTokenAnnotator): (WI.SourceCodeTextEditor.prototype._createBasicBlockAnnotator): Allow a `WI.Script` to not have an associated `WI.Target`, specifically for `WI.LocalScript`. * UserInterface/Views/SourcesNavigationSidebarPanel.js: (WI.SourcesNavigationSidebarPanel): (WI.SourcesNavigationSidebarPanel.prototype.treeElementForRepresentedObject): (WI.SourcesNavigationSidebarPanel.prototype.createContentTreeOutline): (WI.SourcesNavigationSidebarPanel.prototype._compareTreeElements): (WI.SourcesNavigationSidebarPanel.prototype._addLocalOverride): Added. (WI.SourcesNavigationSidebarPanel.prototype._removeResourceOverride): Added. (WI.SourcesNavigationSidebarPanel.prototype._populateCreateResourceContextMenu): (WI.SourcesNavigationSidebarPanel.prototype._handleBootstrapScriptCreated): Added. (WI.SourcesNavigationSidebarPanel.prototype._handleBootstrapScriptDestroyed): Added. (WI.SourcesNavigationSidebarPanel.prototype._handleLocalResourceOverrideAdded): (WI.SourcesNavigationSidebarPanel.prototype._handleLocalResourceOverrideRemoved): (WI.SourcesNavigationSidebarPanel.prototype._handleDebuggerPaused): (WI.SourcesNavigationSidebarPanel.prototype._handleDebuggerResumed): (WI.SourcesNavigationSidebarPanel.prototype._addLocalResourceOverride): Removed. (WI.SourcesNavigationSidebarPanel.prototype._removeLocalResourceOverride): Removed. Add an item in the create resource context menu for creating/focusing the bootstrap script. * UserInterface/Views/ScriptTreeElement.js: (WI.ScriptTreeElement): * UserInterface/Views/BootstrapScriptTreeElement.js: Added. (WI.BootstrapScriptTreeElement): (WI.BootstrapScriptTreeElement.prototype.onattach): (WI.BootstrapScriptTreeElement.prototype.ondetach): (WI.BootstrapScriptTreeElement.prototype.ondelete): (WI.BootstrapScriptTreeElement.prototype.onspace): (WI.BootstrapScriptTreeElement.prototype.canSelectOnMouseDown): (WI.BootstrapScriptTreeElement.prototype.populateContextMenu): (WI.BootstrapScriptTreeElement.prototype.updateStatus): (WI.BootstrapScriptTreeElement.prototype._handleNetworkManagerBootstrapScriptToggled): * UserInterface/Views/BootstrapScriptTreeElement.css: Added. (.item.script.bootstrap .status > input[type="checkbox"]): * UserInterface/Views/LocalResourceOverrideTreeElement.css: (.item.resource.override .status > input[type="checkbox"]): Added. (.item.resource.override .status > div): Removed. Don't show the full bootstrap script URL. Instead, show "Inspector Bootstrap Script". * UserInterface/Views/OpenResourceDialog.js: (WI.OpenResourceDialog.prototype.didPresentDialog): Show the bootstrap script in the open resource dialog. * UserInterface/Base/Utilities.js: (isWebInspectorBootstrapScript): Added. * UserInterface/Controllers/DebuggerManager.js: (WI.DebuggerManager.prototype.scriptDidFail): * UserInterface/Base/ObjectStore.js: (WI.ObjectStore.static _open): (WI.ObjectStore.prototype.async get): Added. Add a generalized object store that can be used for one-off values that need the larger storage capacity of `IndexedDB`. * .eslintrc: * Localizations/en.lproj/localizedStrings.js: LayoutTests: * inspector/page/setBootstrapScript-main-frame.html: Added. * inspector/page/setBootstrapScript-main-frame-expected.txt: Added. * inspector/page/setBootstrapScript-sub-frame.html: Added. * inspector/page/setBootstrapScript-sub-frame-expected.txt: Added. * inspector/page/resources/bootstrap-iframe.html: Added. Canonical link: https://commits.webkit.org/216764@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@251531 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-10-24 06:54:49 +00:00
WI.networkManager.bootstrapScriptEnabled = true;
InspectorTest.log("Reloading page...");
await Promise.all([
InspectorTest.awaitEvent(FrontendTestHarness.Event.TestPageDidLoad),
InspectorTest.reloadPage(),
]);
Web Inspector: provide a way to inject "bootstrap" JavaScript into the page as the first script executed https://bugs.webkit.org/show_bug.cgi?id=195847 <rdar://problem/48950551> Reviewed by Joseph Pecoraro. Source/JavaScriptCore: When debugging webpages, it's often useful to be able to swizzle various functions in order to add extra logs for when they're called (e.g. `Event.prototype.preventDefault`). Sometimes this can be difficult, such as if the page saves a copy of the function and references that instead, in which case it would be helpful to have a way to guarantee that the swizzled code is the first thing evaluated after the context is created. This change adds support for that concept, which has been named Inspector Bootstrap Script. Once created, it will be injected as the first user script to every new global object that is created afterwards. Modifications to the Inspector Bootstrap Script take effect for all new global objects created _after_ the modification happened. * inspector/protocol/Page.json: Add `setBoostrapScript` command. Source/WebCore: When debugging webpages, it's often useful to be able to swizzle various functions in order to add extra logs for when they're called (e.g. `Event.prototype.preventDefault`). Sometimes this can be difficult, such as if the page saves a copy of the function and references that instead, in which case it would be helpful to have a way to guarantee that the swizzled code is the first thing evaluated after the context is created. This change adds support for that concept, which has been named Inspector Bootstrap Script. Once created, it will be injected as the first user script to every new global object that is created afterwards. Modifications to the Inspector Bootstrap Script take effect for all new global objects created _after_ the modification happened. Tests: inspector/page/setBootstrapScript-main-frame.html inspector/page/setBootstrapScript-sub-frame.html * inspector/agents/InspectorPageAgent.h: * inspector/agents/InspectorPageAgent.cpp: (WebCore::InspectorPageAgent::setBootstrapScript): Added. (WebCore::InspectorPageAgent::didClearWindowObjectInWorld): Added. * inspector/InspectorInstrumentation.cpp: (WebCore::InspectorInstrumentation::didClearWindowObjectInWorldImpl): * inspector/agents/page/PageDebuggerAgent.h: * inspector/agents/page/PageDebuggerAgent.cpp: (WebCore::PageDebuggerAgent::didClearWindowObjectInWorld): Added. (WebCore::PageDebuggerAgent::didClearMainFrameWindowObject): Deleted. * inspector/agents/page/PageRuntimeAgent.h: * inspector/agents/page/PageRuntimeAgent.cpp: (WebCore::PageRuntimeAgent::didClearWindowObjectInWorld): Added. (WebCore::PageRuntimeAgent::didCreateMainWorldContext): Deleted. Rename existing global object creation "notifications" for more consistency between agents. Source/WebInspectorUI: When debugging webpages, it's often useful to be able to swizzle various functions in order to add extra logs for when they're called (e.g. `Event.prototype.preventDefault`). Sometimes this can be difficult, such as if the page saves a copy of the function and references that instead, in which case it would be helpful to have a way to guarantee that the swizzled code is the first thing evaluated after the context is created. This change adds support for that concept, which has been named Inspector Bootstrap Script. Once created, it will be injected as the first user script to every new global object that is created afterwards. Modifications to the Inspector Bootstrap Script take effect for all new global objects created _after_ the modification happened. * UserInterface/Controllers/NetworkManager.js: (WI.NetworkManager): (WI.NetworkManager.supportsBootstrapScript): Added. (WI.NetworkManager.get bootstrapScriptURL): Added. (WI.NetworkManager.get bootstrapScriptSourceObjectStoreKey): Added. (WI.NetworkManager.prototype.initializeTarget): (WI.NetworkManager.prototype.get bootstrapScript): Added. (WI.NetworkManager.prototype.get bootstrapScriptEnabled): Added. (WI.NetworkManager.prototype.set bootstrapScriptEnabled): Added. (WI.NetworkManager.prototype.async createBootstrapScript): Added. (WI.NetworkManager.prototype.destroyBootstrapScript): Added. (WI.NetworkManager.prototype._processServiceWorkerConfiguration): (WI.NetworkManager.prototype._handleBootstrapScriptContentDidChange): Added. * UserInterface/Models/LocalScript.js: (WI.LocalScript): (WI.LocalScript.prototype.get editable): Added. (WI.LocalScript.prototype.get supportsScriptBlackboxing): Added. (WI.LocalScript.prototype.requestContentFromBackend): (WI.LocalScript.prototype.handleCurrentRevisionContentChange): Added. * UserInterface/Views/ScriptContentView.js: (WI.ScriptContentView): (WI.ScriptContentView.prototype._contentWillPopulate): (WI.ScriptContentView.prototype._contentDidPopulate): (WI.ScriptContentView.prototype._handleTextEditorContentDidChange): Added. Support editing of `WI.LocalScript` that are specifically marked as such. * UserInterface/Models/Script.js: (WI.Script): (WI.Script.prototype.get displayName): (WI.Script.prototype.get displayURL): (WI.Script.prototype.isMainResource): (WI.Script.prototype._resolveResource): * UserInterface/Views/SourceCodeTextEditor.js: (WI.SourceCodeTextEditor.prototype.customPerformSearch): (WI.SourceCodeTextEditor.prototype._createTypeTokenAnnotator): (WI.SourceCodeTextEditor.prototype._createBasicBlockAnnotator): Allow a `WI.Script` to not have an associated `WI.Target`, specifically for `WI.LocalScript`. * UserInterface/Views/SourcesNavigationSidebarPanel.js: (WI.SourcesNavigationSidebarPanel): (WI.SourcesNavigationSidebarPanel.prototype.treeElementForRepresentedObject): (WI.SourcesNavigationSidebarPanel.prototype.createContentTreeOutline): (WI.SourcesNavigationSidebarPanel.prototype._compareTreeElements): (WI.SourcesNavigationSidebarPanel.prototype._addLocalOverride): Added. (WI.SourcesNavigationSidebarPanel.prototype._removeResourceOverride): Added. (WI.SourcesNavigationSidebarPanel.prototype._populateCreateResourceContextMenu): (WI.SourcesNavigationSidebarPanel.prototype._handleBootstrapScriptCreated): Added. (WI.SourcesNavigationSidebarPanel.prototype._handleBootstrapScriptDestroyed): Added. (WI.SourcesNavigationSidebarPanel.prototype._handleLocalResourceOverrideAdded): (WI.SourcesNavigationSidebarPanel.prototype._handleLocalResourceOverrideRemoved): (WI.SourcesNavigationSidebarPanel.prototype._handleDebuggerPaused): (WI.SourcesNavigationSidebarPanel.prototype._handleDebuggerResumed): (WI.SourcesNavigationSidebarPanel.prototype._addLocalResourceOverride): Removed. (WI.SourcesNavigationSidebarPanel.prototype._removeLocalResourceOverride): Removed. Add an item in the create resource context menu for creating/focusing the bootstrap script. * UserInterface/Views/ScriptTreeElement.js: (WI.ScriptTreeElement): * UserInterface/Views/BootstrapScriptTreeElement.js: Added. (WI.BootstrapScriptTreeElement): (WI.BootstrapScriptTreeElement.prototype.onattach): (WI.BootstrapScriptTreeElement.prototype.ondetach): (WI.BootstrapScriptTreeElement.prototype.ondelete): (WI.BootstrapScriptTreeElement.prototype.onspace): (WI.BootstrapScriptTreeElement.prototype.canSelectOnMouseDown): (WI.BootstrapScriptTreeElement.prototype.populateContextMenu): (WI.BootstrapScriptTreeElement.prototype.updateStatus): (WI.BootstrapScriptTreeElement.prototype._handleNetworkManagerBootstrapScriptToggled): * UserInterface/Views/BootstrapScriptTreeElement.css: Added. (.item.script.bootstrap .status > input[type="checkbox"]): * UserInterface/Views/LocalResourceOverrideTreeElement.css: (.item.resource.override .status > input[type="checkbox"]): Added. (.item.resource.override .status > div): Removed. Don't show the full bootstrap script URL. Instead, show "Inspector Bootstrap Script". * UserInterface/Views/OpenResourceDialog.js: (WI.OpenResourceDialog.prototype.didPresentDialog): Show the bootstrap script in the open resource dialog. * UserInterface/Base/Utilities.js: (isWebInspectorBootstrapScript): Added. * UserInterface/Controllers/DebuggerManager.js: (WI.DebuggerManager.prototype.scriptDidFail): * UserInterface/Base/ObjectStore.js: (WI.ObjectStore.static _open): (WI.ObjectStore.prototype.async get): Added. Add a generalized object store that can be used for one-off values that need the larger storage capacity of `IndexedDB`. * .eslintrc: * Localizations/en.lproj/localizedStrings.js: LayoutTests: * inspector/page/setBootstrapScript-main-frame.html: Added. * inspector/page/setBootstrapScript-main-frame-expected.txt: Added. * inspector/page/setBootstrapScript-sub-frame.html: Added. * inspector/page/setBootstrapScript-sub-frame-expected.txt: Added. * inspector/page/resources/bootstrap-iframe.html: Added. Canonical link: https://commits.webkit.org/216764@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@251531 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-10-24 06:54:49 +00:00
let valueAfterBootstrapScript = await InspectorTest.evaluateInPage(`window.valueFromBootstrapScript`);
InspectorTest.expectEqual(valueAfterBootstrapScript, 42, "'valueFromBootstrapScript' should be '42'.");
},
});
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="runTest()">
<p>Tests for Page.setBootstrapScript command.</p>
</body>
</html>