import { CDPMessageHandlerBase , ExecutionContext , HandlerOptions } from "./CDPMessageHandlerBase" ; import { SourcemapPathTransformer } from "../../sourcemapPathTransformer" ; import { IProjectType } from "../../../../utils/cordovaProjectHelper" ; import { CDP_API_NAMES } from "../CDPAPINames" ; export abstract class SafariCDPMessageHandlerBase extends CDPMessageHandlerBase { protected targetId : string ; protected isTargeted : boolean ; protected iOSAppPackagePath : string ; protected isBackcompatConfigured : boolean ; protected customMessageLastId : number ; constructor ( sourcemapPathTransformer , projectType , options ) { super ( sourcemapPathTransformer , projectType , options ) ; this . targetId = "" ; this . customMessageLastId = 0 ; this . isTargeted = true ; this . isBackcompatConfigured = false ; } protected abstract fixSourcemapLocation ( reqParams ) ; protected abstract fixSourcemapRegexp ( reqParams ) ; protected processDeprecatedConsoleMessage ( event ) { return { method : CDP_API_NAMES . RUNTIME_CONSOLE_API_CALLED , params : { type : event . params . message . type , timestamp : event . params . message . timestamp , args : event . params . message . parameters || [ { type : "string" , value : event . params . message . text } ] , stackTrace : { callFrames : event . params . message . stack || event . params . message . stackTrace } , executionContextId : 1 , } , } ; } protected wrapRequestInTargetedForm ( request ) { return { id : request . id , method : CDP_API_NAMES . TARGET_SEND_MESSAGE_TO_TARGET , params : { id : request . id , message : JSON . stringify ( request ) , targetId : this . targetId , } , } ; } protected configureTargetForIWDPCommunication ( ) { try { this . sendCustomRequestToAppTarget ( CDP_API_NAMES . CONSOLE_ENABLE , { } ) ; this . sendCustomRequestToAppTarget ( CDP_API_NAMES . DEBUGGER_SET_BREAKPOINTS_ACTIVE , { active : true } ) ; } catch ( err ) { } } protected configureDebuggerForIWDPCommunication ( ) { const context = { id : this . customMessageLastId ++ , origin : "" , name : "IOS Execution Context" , auxData : { isDefault : true , type : "page" , frameId : this . targetId } } ; try { this . sendCustomRequestToDebuggerTarget ( CDP_API_NAMES . EXECUTION_CONTEXT_CREATED , { context } , false ) ; } catch ( err ) { throw Error ( "Could not create Execution context" ) ; } } protected sendCustomRequestToDebuggerTarget ( method , params = { } , addMessageId = true ) { let request = { method , params , } ; if ( addMessageId ) { request . id = this . customMessageLastId ++ ; } this . debuggerTarget ?. send ( request ) ; } protected sendCustomRequestToAppTarget ( method , params = { } ) { let request = { id : this . customMessageLastId ++ , method , params , } ; if ( this . isTargeted ) { request = this . wrapRequestInTargetedForm ( request ) ; } this . applicationTarget ?. send ( request ) ; } }