如何从浏览器控制手机屏幕?

iuq*_*iuq 9 mobile android ios

更新
参考资料:perfecto mobile和设备随处可见


我正在开发基于云的移动测试解决方案,该解决方案应该支持iOS和Android.它需要从浏览器处理连接的移动设备.

我了解到移动设备有一个代理程序类型的程序(需要设备根植)安装

  • 将移动屏幕流式传输到浏览器
  • 并注入事件

有没有其他方法可以实现这一点,可能没有root/jail打破设备?

这个问题可能看起来很广泛,但我一直在努力想要朝着正确的方向前进.

对于iOS,我从这个SOF问题中获取线索.

任何指针都很受欢迎.


更新1:
这个问题接近我正在寻找的问题.

更新2: 我找到了Android设备的Android屏幕库,并在几台设备上进行了测试.它不要求设备被植根,但需要在每次设备重启时从命令行重新启动服务,并且无法在Lollipop上运行它..

更新3: 虽然Android屏幕库有助于在没有生根的情况下捕获屏幕,但它对注入事件没有帮助.甚至屏幕捕获似乎有些错误 - 有时用黑色补丁捕获并且在棒棒糖上不起作用!

更新4: 参考:perfecto mobile和设备随处可见 它们似乎ADB用于处理许多事情,如应用程序安装/卸载,通过发送事件adb shell input tap x y.任何人都可以解释一下吗?

更新5: 我也碰到过这种SO帖子由阿德里安·泰勒,一名前工程师的RealVNC.这是最详细的解释.虽然Android Lollipop有MediaProjection API,但它似乎将屏幕截图存储为sdcard上的MP4文件.此外,根据谷歌仪表板 - 2015年8月更新Lollipop仍然是Android安装基数的15%左右,所以必须考虑Kitkat的任何解决方案.

更新6: 我找到了libvncserver,想知道它是否能完成这项工作.我将测试并发布结果.

谢谢

Pre*_*dea 4

使用 WebKit,这将使您尽可能接近并且仍然更有可能通过 Apple 的批准流程

这是一个简单的示例,这基本上在网页上创建一个选择器,在应用程序上将字符串值发送给我,您处理该值并发回结果,然后将其作为网页的标题发布。

<h2 id="headline">loading...</h2>
<select id="selector">
    <option value="systemVersion" selected>iOS Version</option>
    <option value="systemName">System Name</option>
    <option value="name">Device Name</option>
    <option value="model">Device Model</option>
    <option value="userInterfaceIdiom">User Interface</option>
    <option value="identifierForVendor">Vendor ID</option>
</select>
Run Code Online (Sandbox Code Playgroud)

这是 JavaScript:

var headline = $("#headline");
var selection = $("#selector");

function set_headline (text) {
    headline.text(text);
}

function call_native () {
    var prop = selection.val();
    set_headline("asked for " + prop + "...");
    window.webkit.messageHandlers.observe.postMessage(prop);
}

setTimeout(call_native, 1000);
selection.on("change", call_native);
Run Code Online (Sandbox Code Playgroud)

在应用程序端,您设置以下内容:

//配置webView并将webview放置在屏幕上

[controller addScriptMessageHandler:self name:@"observe"];
configuration.userContentController = controller;
NSURL *jsbin = [NSURL URLWithString:k_JSBIN_URL];

_webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:configuration];
[_webView loadRequest:[NSURLRequest requestWithURL:jsbin]];
[self.view addSubview:_webView];
Run Code Online (Sandbox Code Playgroud)

处理 webView 事件:

-(void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
{
// Check to make sure the name is correct
    if ([message.name isEqualToString:@"observe"]) {
        // Log the message received
        NSLog(@"Received event %@", message.body);

        // Then pull something from the device using the message body
        NSString *version = [[UIDevice currentDevice] valueForKey:message.body];

        // Execute some JavaScript using the result
        NSString *exec_template = @"set_headline(\"received: %@\");";
        NSString *exec = [NSString stringWithFormat:exec_template, version];
        [_webView evaluateJavaScript:exec completionHandler:nil];
    }
}
Run Code Online (Sandbox Code Playgroud)