Symptom
If the script tag content in the custom HTML file is not loaded after onInterceptRequest is used to intercept the src link of the web page and the custom HTML file is returned, you need to check the script path and loading mode.
Solution
If only setResponseData is set for the interceptor, the kernel cannot identify the HTML file. You must also set parameters such as setResponseEncoding, setResponseMimeType, and setResponseHeader for the kernel to identify the HTML file. The code snippet is as follows:
Web({ src: 'www.example.com',controller: this.controller })
.onInterceptRequest((event) => {
console.log('url:' + event.request.getRequestUrl())
this.responseWeb = new WebResourceResponse();
let head1: Header = {
headerKey: "Connection",
headerValue: "keep-alive"
}
let length = this.heads.push(head1)
this.responseWeb.setResponseHeader(this.heads)
this.responseWeb.setResponseData(this.webData)
this.responseWeb.setResponseEncoding('utf-8')
this.responseWeb.setResponseMimeType('text/html')
this.responseWeb.setResponseCode(200)
this.responseWeb.setReasonMessage('OK')
return this.responseWeb
}) Reference