@@ -30,13 +30,14 @@ import { getComputedVisibilityFnName } from '@secret-agent/interfaces/jsPathFnNa
3030import IAwaitedOptions from '../interfaces/IAwaitedOptions' ;
3131import RequestGenerator , { getRequestIdOrUrl } from './Request' ;
3232import CookieStorage , { createCookieStorage } from './CookieStorage' ;
33- import Agent from './Agent' ;
33+ import Agent , { IState as IAgentState } from './Agent' ;
3434import { delegate as AwaitedHandler , getAwaitedPathAsMethodArg } from './SetupAwaitedHandler' ;
3535import CoreFrameEnvironment from './CoreFrameEnvironment' ;
3636import Tab from './Tab' ;
3737import { IMousePosition } from '../interfaces/IInteractions' ;
3838
3939const { getState, setState } = StateMachine < FrameEnvironment , IState > ( ) ;
40+ const agentState = StateMachine < Agent , IAgentState > ( ) ;
4041const awaitedPathState = StateMachine <
4142 any ,
4243 { awaitedPath : AwaitedPath ; awaitedOptions : IAwaitedOptions }
@@ -67,6 +68,18 @@ export default class FrameEnvironment {
6768 tab,
6869 coreFrame,
6970 } ) ;
71+ async function sendToFrameEnvironment ( pluginId : string , ...args : any [ ] ) : Promise < any > {
72+ return ( await coreFrame ) . commandQueue . run (
73+ 'FrameEnvironment.runPluginCommand' ,
74+ pluginId ,
75+ args ,
76+ ) ;
77+ }
78+
79+ for ( const clientPlugin of agentState . getState ( secretAgent ) . clientPlugins ) {
80+ if ( clientPlugin . onFrameEnvironment )
81+ clientPlugin . onFrameEnvironment ( secretAgent , this , sendToFrameEnvironment ) ;
82+ }
7083 }
7184
7285 public get isMainFrame ( ) : Promise < boolean > {
@@ -77,6 +90,21 @@ export default class FrameEnvironment {
7790 return getCoreFrameEnvironment ( this ) . then ( x => x . frameId ) ;
7891 }
7992
93+ public get children ( ) : Promise < FrameEnvironment [ ] > {
94+ return getState ( this ) . tab . frameEnvironments . then ( async frames => {
95+ const frameId = await this . frameId ;
96+
97+ const childFrames : FrameEnvironment [ ] = [ ] ;
98+ for ( const frame of frames ) {
99+ const parentFrameId = await frame . parentFrameId ;
100+ if ( parentFrameId === frameId ) {
101+ childFrames . push ( frame ) ;
102+ }
103+ }
104+ return childFrames ;
105+ } ) ;
106+ }
107+
80108 public get url ( ) : Promise < string > {
81109 return getCoreFrameEnvironment ( this ) . then ( x => x . getUrl ( ) ) ;
82110 }
@@ -88,9 +116,7 @@ export default class FrameEnvironment {
88116 }
89117
90118 public get parentFrameId ( ) : Promise < number | null > {
91- return getCoreFrameEnvironment ( this )
92- . then ( x => x . getFrameMeta ( ) )
93- . then ( x => x . parentFrameId ) ;
119+ return getCoreFrameEnvironment ( this ) . then ( x => x . parentFrameId ) ;
94120 }
95121
96122 public get cookieStorage ( ) : CookieStorage {
0 commit comments