@@ -3,19 +3,19 @@ const {getUnsafeWindow} = require("../utils/scope-util");
33const { JsonpCallbackFunctionAnalyzer} = require ( "../analyzer/response-analyzer" ) ;
44
55/**
6- * 表示一个条件断点
6+ * 表示一个jsonp的条件断点
77 */
88class Debugger {
99
1010 /**
1111 * 创建一个断点
1212 *
13- * @param urlPattern {String | RegExp} 用于与script类型的请求的URL做匹配进入断点
14- * @param enableRequestDebugger {Boolean} 是否开启请求断点,开启请求断点会在请求发送之前进入断点
15- * @param enableResponseDebugger {Boolean} 是否开启响应断点,开启响应断点会在响应处理之前进入断点
16- * @param callbackFunctionParamName {String} 传递jsonp回调函数名字的参数,比如 "callback"
13+ * @param urlPattern {String | RegExp} 用于与script类型的请求的URL做匹配进入断点,只有这一个是必须指定的
14+ * @param enableRequestDebugger {Boolean} 是否开启请求断点,开启请求断点会在请求发送之前进入断点,不指定的话默认开启
15+ * @param enableResponseDebugger {Boolean} 是否开启响应断点,开启响应断点会在响应处理之前进入断点,不指定的话默认开启
16+ * @param callbackFunctionParamName {String} 传递jsonp回调函数名字的参数,比如 "callback",如果不指定的话会自动推测
1717 */
18- constructor ( urlPattern , enableRequestDebugger , enableResponseDebugger , callbackFunctionParamName ) {
18+ constructor ( urlPattern , enableRequestDebugger = true , enableResponseDebugger = true , callbackFunctionParamName ) {
1919 this . urlPattern = urlPattern ;
2020 this . enableRequestDebugger = enableRequestDebugger ;
2121 this . enableResponseDebugger = enableResponseDebugger ;
@@ -31,7 +31,7 @@ class Debugger {
3131 test ( scriptContext ) {
3232
3333 // 首先URL要能够匹配得上
34- if ( ! this . testUrlPattern ( scriptContext . URL ) ) {
34+ if ( ! this . testUrlPattern ( scriptContext . url ) ) {
3535 return ;
3636 }
3737
@@ -44,16 +44,20 @@ class Debugger {
4444 if ( this . enableResponseDebugger ) {
4545
4646 // 如果没有指定jsonp函数的名字的话,则尝试自动抽取函数名字
47- if ( ! this . callbackFunctionParamName ) {
48- this . callbackFunctionParamName = new JsonpCallbackFunctionAnalyzer ( ) . parseScriptContext ( scriptContext ) ;
47+ let jsonpCallbackFunctionName = this . callbackFunctionParamName ;
48+ if ( ! jsonpCallbackFunctionName ) {
49+ jsonpCallbackFunctionName = scriptContext . requestContext . getJsonpCallbackFuncName ( ) ;
4950 }
50- if ( ! this . callbackFunctionParamName ) {
51+ if ( ! jsonpCallbackFunctionName ) {
5152 // TODO 2023-8-22 01:00:27 完善错误提示信息
5253 throw new Error ( "must give me analyzer function param name, example: callback" ) ;
5354 }
5455
5556 // 为响应体中的回调函数增加hook
56- new ObjectFunctionHook ( getUnsafeWindow ( ) , this . callbackFunctionParamName ) . addHook ( ) ;
57+ new ObjectFunctionHook ( getUnsafeWindow ( ) , jsonpCallbackFunctionName ) . addHook ( function ( ) {
58+ // 这里是脚本的响应断点,已经拦截到响应,跟进去holder函数就行了
59+ debugger ;
60+ } ) ;
5761 }
5862
5963 }
0 commit comments