cocos creator3.6.0打包作为webview嵌入app报错

解决了,app内本地加载的时候,在原来的fetchLocal方法里,将status: xhr.status写死为200就可以了

请问下 这个代码要加在哪儿呢?

加在构建后的 src/system.bundle.js 中,可以放到template模板里

好的 谢谢大佬解答

这个要弄个httpserver吧,直接 打开是不行的

这个要怎么加能详细说下吗,打包后得system.bundle.js 是压缩了得

在调试模式下构建后改吧,改完放构建模板里,这个文件加密不加密没什么意义,不怕人偷

请问是加到那个文件里面呢

加在构建后的 src/system.bundle.js 中

好的 非常感谢

cocos creator3.7.0打包作为webview嵌入app报错

调试模式下,src/system.bundle.js 中 添加 fetchLocal(url) , 3.7.0出现新的错误:

在Mac系统 的浏览器可复现,编译调试模式web-mobile,src/system.bundle.js 中添加 fetchLocal(url) ,浏览器访问本地web-mobile。
CompileError: WebAssembly.instantiate(): section (code 1, “Type”) extends past end of the module (length 11493359, remaining bytes 530828) @+8

3.7.0 版本不添加 fetchLocal 也会出现 :
URL scheme “file” is not supported 或 fetch接口 报错

用了物理引擎的报错、 v1.2.0无法运行在安卓webview环境下的问题、已解决

我这边物理引擎也报错了,但是是偶现的,频繁反复打开webview就会出现,因为没用到物理引擎,所以我直接去掉了,不知道你是怎么解决的呢

App安卓端webview嵌入web小游戏报错显示:
参考链接(https://forum.cocos.org/t/topic/141659)

Error1:(没有添加fetchLocal)
error fetching sysytemjs-import map file’…
unable to resolve bare specifier ’cc‘ …

Error2:(没有添加fetchLocal)
Fetch API cannot load file:///xxx/src/import-map.json. URL scheme “file” is not supported.

Error3:(有重构fetchLocal,XMLHttpRequest写死status: 200)
rangError: status must be between 200 and 599

Error4:(有重构fetchLocal,项目内使用了物理引擎,在修改XMLHttpRequest的responseType 类型)
instantiated.js:62486 CompileError: WebAssembly.instantiate(): expected 11493359 bytes, fell off end @+13
errorReport @ instantiated.js:62486

修改文件添加重构方法:web-mobile/src/system.bundle.js
(注意:使用调试模式代码 覆盖 压缩代码),
如果是rpk包先解压找到对应system.bundil.js 修改

function fetchLocal(url) { // 不完善接口,用了物理引擎会出现Error4
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest
xhr.onload = function() {
resolve(new Response(xhr.responseText, {status: 200}))
}
xhr.onerror = function() {
reject(new TypeError(‘Local request failed’))
}
xhr.open(‘GET’, url)
xhr.send(null)
})
}
window.fetch = fetchLocal;

function fetchLocal(url) {
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest
xhr.onload = function () {
resolve(new Response(xhr.response, {
status: 200
}))
}
xhr.onerror = function () {
reject(new TypeError(‘Local request failed’))
}
xhr.open(‘GET’, url)
xhr.responseType = ‘arraybuffer’;
xhr.send(null)
})
};
window.fetch = fetchLocal;

5赞

哥,问一下 ios使用webview本地加载web-mobile可以过审吗?

没有尝试过iOS 、apk 使用webview 加载 H5链接 应该是可行的,Android 小游戏平台app是这个思路

一看大佬的名字就知道经验丰富,灵不灵?