-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from GoogleChrome/mzgoddard/missing-context-d…
…estroyed-workaround Detect stale contexts
- Loading branch information
Showing
13 changed files
with
442 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* @file | ||
* Strings passed to `chrome.debugger.sendCommand` and received from | ||
* `chrome.debugger.onEvent` callbacks. | ||
*/ | ||
|
||
import {ProtocolMapping} from 'devtools-protocol/types/protocol-mapping'; | ||
|
||
/** @see https://chromedevtools.github.io/devtools-protocol/tot/Page/#methods */ | ||
export enum PageDebuggerMethod { | ||
disable = 'Page.disable', | ||
enable = 'Page.enable', | ||
} | ||
|
||
/** @see https://chromedevtools.github.io/devtools-protocol/tot/Page/#events */ | ||
export enum PageDebuggerEvent { | ||
domContentEventFired = 'Page.domContentEventFired', | ||
frameAttached = 'Page.frameAttached', | ||
frameDetached = 'Page.frameDetached', | ||
frameNavigated = 'Page.frameNavigated', | ||
frameRequestedNavigation = 'Page.frameRequestedNavigation', | ||
frameStartedLoading = 'Page.frameStartedLoading', | ||
frameStoppedLoading = 'Page.frameStoppedLoading', | ||
lifecycleEvent = 'Page.lifecycleEvent', | ||
loadEventFired = 'Page.loadEventFired', | ||
} | ||
|
||
/** @see https://chromedevtools.github.io/devtools-protocol/tot/Page/#types */ | ||
export type PageDebuggerEventParams<Name extends PageDebuggerEvent> = | ||
ProtocolMapping.Events[Name]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import {filter, map, Observable} from 'rxjs'; | ||
import {chrome} from '../chrome'; | ||
import {fromChromeEvent} from '../utils/rxChrome'; | ||
import {DebuggerAttachEventController} from './DebuggerAttachEventController'; | ||
import {Audion} from './Types'; | ||
|
||
type DebuggerDomain = 'page' | 'webAudio'; | ||
|
||
interface DebuggerEventsOptions<D extends DebuggerDomain> { | ||
domain: D; | ||
} | ||
|
||
type DebuggerDomainEvent<D extends DebuggerDomain> = D extends 'page' | ||
? Audion.PageEvent | ||
: D extends 'webAudio' | ||
? Audion.WebAudioEvent | ||
: never; | ||
|
||
export class DebuggerEventsObservable< | ||
D extends DebuggerDomain, | ||
> extends Observable<DebuggerDomainEvent<D>> { | ||
constructor( | ||
public attachController: DebuggerAttachEventController, | ||
public options: DebuggerEventsOptions<D>, | ||
) { | ||
super((subscriber) => { | ||
attachController.attachInterest$.increment(); | ||
attachController[options.domain + 'EventInterest$'].increment(); | ||
const subscription = fromChromeEvent(chrome.debugger.onEvent) | ||
.pipe( | ||
map(([debuggeeId, method, params]) => ({method, params})), | ||
filter(({method}) => | ||
method.toLowerCase().startsWith(options.domain.toLowerCase()), | ||
), | ||
) | ||
.subscribe(subscriber); | ||
subscription.add(() => { | ||
attachController.attachInterest$.decrement(); | ||
attachController[options.domain + 'EventInterest$'].decrement(); | ||
}); | ||
return subscription; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.