diff --git a/devtools/target.js b/devtools/target.js index 1190553..48c7790 100644 --- a/devtools/target.js +++ b/devtools/target.js @@ -37,13 +37,12 @@ window.onload = function () { function resetDevtools() { const window = devtoolsIframe.contentWindow setTimeout(() => { - window.runtime.loadLegacyModule('core/sdk/sdk-legacy.js').then(() => { - const SDK = window.SDK - for (const resourceTreeModel of SDK.TargetManager.instance().models( - SDK.ResourceTreeModel + window.runtime.loadLegacyModule('core/sdk/sdk.js').then(SDKModule => { + for (const resourceTreeModel of SDKModule.TargetManager.TargetManager.instance().models( + SDKModule.ResourceTreeModel.ResourceTreeModel )) { resourceTreeModel.dispatchEventToListeners( - SDK.ResourceTreeModel.Events.WillReloadPage, + SDKModule.ResourceTreeModel.Events.WillReloadPage, resourceTreeModel ) } @@ -69,5 +68,7 @@ function resetDevtools() { sendToChobitsu({ method: 'CSS.enable' }) sendToChobitsu({ method: 'Overlay.enable' }) sendToDevtools({ method: 'DOM.documentUpdated' }) + sendToChobitsu({ method: 'Page.enable' }) + sendToDevtools({ method: 'Page.loadEventFired' }) }, 0) } diff --git a/src/domains/DOM.ts b/src/domains/DOM.ts index b1d8c6d..adca8c8 100644 --- a/src/domains/DOM.ts +++ b/src/domains/DOM.ts @@ -307,6 +307,12 @@ export function getTopLayerElements(): DOM.GetTopLayerElementsResponse { } } +export function getNodesForSubtreeByStyle(): DOM.GetNodesForSubtreeByStyleResponse { + return { + nodeIds: [], + } +} + function parseAttributes(str: string) { str = `
` diff --git a/src/domains/Input.ts b/src/domains/Input.ts index 9d4cbf3..3ed624a 100644 --- a/src/domains/Input.ts +++ b/src/domains/Input.ts @@ -24,13 +24,7 @@ export function emulateTouchFromMouseEvent( case 'mouseReleased': triggerTouchEvent('touchend', el, x, y) if (isClick) { - el.dispatchEvent( - new MouseEvent('click', { - bubbles: true, - cancelable: true, - view: window, - }) - ) + triggerMouseEvent('click', el, x, y) } isClick = false break @@ -42,6 +36,47 @@ export function emulateTouchFromMouseEvent( } } +export function dispatchMouseEvent(params: Input.DispatchMouseEventRequest) { + const { type, x, y, deltaX, deltaY } = params + + const el = document.elementFromPoint(x, y) || document.documentElement + + switch (type) { + case 'mousePressed': + isClick = true + triggerMouseEvent('mousedown', el, x, y) + break + case 'mouseMoved': + isClick = false + triggerMouseEvent('mousemove', el, x, y) + break + case 'mouseReleased': + triggerMouseEvent('mouseup', el, x, y) + if (isClick) { + triggerMouseEvent('click', el, x, y) + } + isClick = false + break + case 'mouseWheel': + if (!isUndef(deltaX) && !isUndef(deltaY)) { + triggerScroll(el, deltaX, deltaY) + } + break + } +} + +function triggerMouseEvent(type: string, el: Element, x: number, y: number) { + el.dispatchEvent( + new MouseEvent(type, { + bubbles: true, + cancelable: true, + view: window, + clientX: x, + clientY: y, + }) + ) +} + function triggerTouchEvent(type: string, el: Element, x: number, y: number) { const touch = new Touch({ identifier: 0, diff --git a/src/domains/Storage.ts b/src/domains/Storage.ts index 3ef2b45..94ca2ac 100644 --- a/src/domains/Storage.ts +++ b/src/domains/Storage.ts @@ -1,6 +1,7 @@ import each from 'licia/each' import rmCookie from 'licia/rmCookie' import safeStorage from 'licia/safeStorage' +import connector from '../lib/connector' import { getCookies } from './Network' import Protocol from 'devtools-protocol' import Storage = Protocol.Storage @@ -39,7 +40,7 @@ export function getTrustTokens(): Storage.GetTrustTokensResponse { export function getStorageKeyForFrame(): Storage.GetStorageKeyForFrameResponse { return { - storageKey: 'chobitsu', + storageKey: location.origin, } } @@ -53,3 +54,18 @@ export function getSharedStorageMetadata(): Storage.GetSharedStorageMetadataResp }, } } + +export function setStorageBucketTracking() { + connector.trigger('Storage.storageBucketCreatedOrUpdated', { + bucketInfo: { + bucket: { + storageKey: location.origin, + }, + durability: 'relaxed', + expiration: 0, + id: '0', + persistent: false, + quota: 0, + }, + }) +} diff --git a/src/index.ts b/src/index.ts index 14a4d37..5dacfa5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -117,7 +117,7 @@ chobitsu.register('Storage', { ...Storage, setInterestGroupTracking: noop, setSharedStorageTracking: noop, - setStorageBucketTracking: noop, + trackIndexedDBForStorageKey: noop, untrackCacheStorageForOrigin: noop, untrackIndexedDBForOrigin: noop, trackCacheStorageForOrigin: noop,