diff options
Diffstat (limited to 'devtools/shared/resources/transformers')
6 files changed, 127 insertions, 0 deletions
diff --git a/devtools/shared/resources/transformers/console-messages.js b/devtools/shared/resources/transformers/console-messages.js new file mode 100644 index 0000000000..536c3e2b6e --- /dev/null +++ b/devtools/shared/resources/transformers/console-messages.js @@ -0,0 +1,23 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +// eslint-disable-next-line mozilla/reject-some-requires +loader.lazyRequireGetter( + this, + "getAdHocFrontOrPrimitiveGrip", + "devtools/client/fronts/object", + true +); + +module.exports = function({ resource, targetFront }) { + if (Array.isArray(resource.message.arguments)) { + // We might need to create fronts for each of the message arguments. + resource.message.arguments = resource.message.arguments.map(arg => + getAdHocFrontOrPrimitiveGrip(arg, targetFront) + ); + } + return resource; +}; diff --git a/devtools/shared/resources/transformers/error-messages.js b/devtools/shared/resources/transformers/error-messages.js new file mode 100644 index 0000000000..8d6e2b821e --- /dev/null +++ b/devtools/shared/resources/transformers/error-messages.js @@ -0,0 +1,31 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +// eslint-disable-next-line mozilla/reject-some-requires +loader.lazyRequireGetter( + this, + "getAdHocFrontOrPrimitiveGrip", + "devtools/client/fronts/object", + true +); + +module.exports = function({ resource, targetFront }) { + if (resource?.pageError?.errorMessage) { + resource.pageError.errorMessage = getAdHocFrontOrPrimitiveGrip( + resource.pageError.errorMessage, + targetFront + ); + } + + if (resource?.pageError?.exception) { + resource.pageError.exception = getAdHocFrontOrPrimitiveGrip( + resource.pageError.exception, + targetFront + ); + } + + return resource; +}; diff --git a/devtools/shared/resources/transformers/moz.build b/devtools/shared/resources/transformers/moz.build new file mode 100644 index 0000000000..0a124db7a8 --- /dev/null +++ b/devtools/shared/resources/transformers/moz.build @@ -0,0 +1,11 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +DevToolsModules( + "console-messages.js", + "error-messages.js", + "network-events.js", + "storage-local-storage.js", + "storage-session-storage.js", +) diff --git a/devtools/shared/resources/transformers/network-events.js b/devtools/shared/resources/transformers/network-events.js new file mode 100644 index 0000000000..55a0efea77 --- /dev/null +++ b/devtools/shared/resources/transformers/network-events.js @@ -0,0 +1,16 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const { + getUrlDetails, + // eslint-disable-next-line mozilla/reject-some-requires +} = require("devtools/client/netmonitor/src/utils/request-utils"); + +module.exports = function({ resource }) { + resource.urlDetails = getUrlDetails(resource.url); + resource.startedMs = Date.parse(resource.startedDateTime); + return resource; +}; diff --git a/devtools/shared/resources/transformers/storage-local-storage.js b/devtools/shared/resources/transformers/storage-local-storage.js new file mode 100644 index 0000000000..d9d78e1f10 --- /dev/null +++ b/devtools/shared/resources/transformers/storage-local-storage.js @@ -0,0 +1,23 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const { + TYPES: { LOCAL_STORAGE }, +} = require("devtools/shared/resources/resource-watcher"); + +const { Front, types } = require("devtools/shared/protocol.js"); + +module.exports = function({ resource, watcherFront, targetFront }) { + if (!(resource instanceof Front) && watcherFront) { + // instantiate front for local storage + resource = types.getType("localStorage").read(resource, targetFront); + resource.resourceType = LOCAL_STORAGE; + resource.resourceId = LOCAL_STORAGE; + resource.resourceKey = "localStorage"; + } + + return resource; +}; diff --git a/devtools/shared/resources/transformers/storage-session-storage.js b/devtools/shared/resources/transformers/storage-session-storage.js new file mode 100644 index 0000000000..2a346fbfaf --- /dev/null +++ b/devtools/shared/resources/transformers/storage-session-storage.js @@ -0,0 +1,23 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const { + TYPES: { SESSION_STORAGE }, +} = require("devtools/shared/resources/resource-watcher"); + +const { Front, types } = require("devtools/shared/protocol.js"); + +module.exports = function({ resource, watcherFront, targetFront }) { + if (!(resource instanceof Front) && watcherFront) { + // instantiate front for session storage + resource = types.getType("sessionStorage").read(resource, targetFront); + resource.resourceType = SESSION_STORAGE; + resource.resourceId = SESSION_STORAGE; + resource.resourceKey = "sessionStorage"; + } + + return resource; +}; |