Jione
V2EX  ›  Android

问下各位 Android 大佬, 为什么两个 android App 执行同一个 js,执行结果不同!

  •  
  •   Jione · Oct 16, 2021 · 15310 views
    This topic created in 1847 days ago, the information mentioned may be changed or developed.

    问下各位 Android 大佬, 为什么两个 android App 执行同一个 js,执行结果不同! 我用手机浏览器画的 canvas 转 base64 用 A app 执行 js 画 canvas 转 base64 没问题和浏览器画的一致 用 B app 执行 js 画 canvas 转 base64 和浏览器不一致

    执行 js 是用的同样的代码!

    17 replies  •  2021-10-18 10:28:28 +08:00
    Jione
    Jione
    OP
    Oct 16, 2021
    1
    问下各位 Android 大佬, 为什么两个 android App 执行同一个 js,执行结果不同!
    我用手机浏览器画的 canvas 转 base64
    用 A app 执行 js 画 canvas 转 base64 没问题和浏览器画的一致
    用 B app 执行 js 画 canvas 转 base64 和浏览器不一致

    执行 js 是用的同样的代码!
    fugui2
    fugui2
    Oct 16, 2021
    2
    show your code
    Jione
    Jione
    OP
    Oct 16, 2021
    3
    @fugui2 应该不是 js 代码和调用 js 的这个代码问题吧,
    ozzzm
    ozzzm
    Oct 16, 2021
    4
    webview 的内核版本不同? webkit 版本内核 之类的
    InDom
    InDom
    Oct 16, 2021
    5
    之前有个 利用 Canvas 画板计算用户指纹来识别跟踪用户。
    Jione
    Jione
    OP
    Oct 16, 2021
    6
    @MonkeyD1 都对比了是一样的
    Jione
    Jione
    OP
    Oct 16, 2021
    7
    @InDom 对我是正在做这个,但是不知道两个同样的 app 执行两个同样的代码结果不一样
    stardust21
    stardust21
    Oct 16, 2021
    8
    原因应该就是 4 楼说的,不同的 APP 用了不同的 webview 内核
    deplivesb
    deplivesb
    Oct 16, 2021❤️3
    9
    到现在也没见到代码,全靠广大网友猜
    又一个悬丝诊脉
    damao2250
    damao2250
    Oct 16, 2021
    10
    悬丝诊脉
    Jione
    Jione
    OP
    Oct 16, 2021
    11
    @stardust21 两个 app 的运行 js 代码
    String js = "";
    try {
    InputStream is = null;
    is = getAssets().open("main.js");
    int size = is.available();
    byte[] buffer = new byte[size];
    is.read(buffer);
    is.close();
    js = new String(buffer);

    } catch (IOException e) {
    e.printStackTrace();
    }
    JsEvaluator jsEvaluator = new JsEvaluator(this);

    jsEvaluator.callFunction(js,
    new JsCallback() {
    @Override
    public void onResult(String result) {
    // Process result here.
    // This method is called in the UI thread.
    MyLog.loge("result:"+result);
    MyLog.log("md5:" + md5(result));
    }
    @Override
    public void onError(String errorMessage) {
    MyLog.log("errorMessage:" + errorMessage);

    // Process JavaScript error here.
    // This method is called in the UI thread.
    }
    }, "webglFp");
    Jione
    Jione
    OP
    Oct 16, 2021
    12
    @deplivesb 代码已发
    WebKit
    WebKit
    Oct 17, 2021 via Android
    13
    手机版本?还是说同一个手机装的两个 app ?如果是国内的 app,可以试试卸载腾讯系软件,然后卸载重装这两个 app 试试
    ruri
    ruri
    Oct 17, 2021
    14
    webview 你就别指望不同设备执行结果会一样了,这也是为什么现在很多 APP 会集成腾讯 x5 的主要原因,就是为了让自己的 APP 在每个设备上运行结果相同,减少开发调试精力。
    其实较新版本的谷歌官方或 AOSP webview 都没什么毛病,但你架不住有些国内厂商会魔改自己手机系统里的 webview,哪怕是微调一些 webview 的默认参数,都会导致你的代码运行效果和原版大不一样。
    lisongeee
    lisongeee
    Oct 17, 2021
    15
    @Jione 你发的是 java 代码,还有 js 代码呢?
    zoharSoul
    zoharSoul
    Oct 17, 2021
    16
    @Jione 要的是 js 代码, Java 代码有啥好看的
    Jione
    Jione
    OP
    Oct 18, 2021
    17
    @ruri 两个 app 都是我自己的 app ,没有集成其他内核
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   866 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 21:12 · PVG 05:12 · LAX 13:12 · JFK 16:12
    ♥ Do have faith in what you're doing.