Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

字节小程序 WebView 无法相应 onMessage #10005

Open
felix9ia opened this issue Aug 7, 2021 · 0 comments
Open

字节小程序 WebView 无法相应 onMessage #10005

felix9ia opened this issue Aug 7, 2021 · 0 comments
Labels
F-react Framework - React T-tt Target - 编译到字节跳动小程序 V-3 Version - 3.x

Comments

@felix9ia
Copy link

felix9ia commented Aug 7, 2021

相关平台

字节跳动小程序

小程序基础库: 2.14.0.1
使用框架: React

复现步骤

navigateBack 微信和字节都能触发返回,但 onMessage 微信小程序能响应,但是字节小程序就无法响应。

web端


  navigateBack = (remoteUrl) => {
    this.navigateBackToWechat(remoteUrl);
    this.navigateBackToTt(remoteUrl)
  }

  navigateBackToWechat = (remoteUrl) => {
    wx.miniProgram.postMessage({
      data: {
        imgData: remoteUrl,
      },
    });
    wx.miniProgram.navigateBack();
  }


  navigateBackToTt = (remoteUrl) => {
    console.log("navigateBackToTt: ", window.tt);
    window.tt.miniProgram.postMessage({
      data: {
        imgData: remoteUrl,
      },
    });
    window.tt.miniProgram.navigateBack();
  }

小程序端

 handleMessage = async ({detail}) => {
    const base64Url = detail.data[0].imgData;
    console.log('base64Url: ', base64Url);
    await Taro.setStorage({
      key: "tempImgUrl",
      data: base64Url
    });

  }

  render() {
    const {webviewUrl} = this.state;
    console.log("render webviewUrl :", webviewUrl);
    return (
      <View className="album-body-wrapper">

        <WebView src={webviewUrl} onMessage={this.handleMessage}></WebView>
      </View>
    );
  }

期望结果

字节小程序能够像微信小程序一样,触发 onMessage 函数

实际结果

无法触发 onMessage 函数

环境信息

👽 Taro v3.0.8


  Taro CLI 3.0.8 environment info:
    System:
      OS: macOS 11.2.3
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 15.4.0 - ~/.nvm/versions/node/v15.4.0/bin/node
      Yarn: 1.21.1 - ~/.yarn/bin/yarn
      npm: 7.0.15 - ~/.nvm/versions/node/v15.4.0/bin/npm
    npmPackages:
      @tarojs/cli: 3.2.13 => 3.2.13 
      @tarojs/components: 3.2.13 => 3.2.13 
      @tarojs/mini-runner: 3.2.13 => 3.2.13 
      @tarojs/react: 3.2.13 => 3.2.13 
      @tarojs/runtime: 3.2.13 => 3.2.13 
      @tarojs/taro: 3.2.13 => 3.2.13 
      @tarojs/webpack-runner: 3.2.13 => 3.2.13 
      babel-preset-taro: 3.2.13 => 3.2.13 
      eslint-config-taro: 3.2.13 => 3.2.13 
      react: ^16.10.0 => 16.14.0 
      taro-ui: ^3.0.0-alpha.3 => 3.0.0-alpha.10 

@taro-bot2 taro-bot2 bot added F-react Framework - React T-tt Target - 编译到字节跳动小程序 V-3 Version - 3.x labels Aug 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-tt Target - 编译到字节跳动小程序 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

1 participant