Closed sonygod closed 3 years ago
Please provide a compilable snippet.
package;
import puppeteer.EmulateOptions;
import Puppeteer;
import puppeteer.devices.Device;
import puppeteer.Browser;
using tink.CoreApi;
@await
class Main {
@async
public static function main() {
var browser:Browser = @await Puppeteer.launch({headless: false, devtools: true}).toPromise();
var page=@await browser.newPage().toPromise();
// var d:Device={name:'iPhone X'};
//@await page.emulate(d).toPromise();
@await page.setViewport({
width: 375,
height: 667,
isMobile: true,
hasTouch:true
}).toPromise();
@await page.goto('https://www.baidu.com').toPromise();
}
}
I think you forgot to return something for your @async
function
/**
Sets the viewport of the page.
**/
function setViewport(viewport:Viewport):js.lib.Promise<Void>;
js.lib.Promise <Void> can not use in **.toPromise();**
and the js code is
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({ headless: false, devtools: true });
const page = await browser.newPage();
await page.setUserAgent('Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1');
await page.setViewport({ width: 375, height: 812 });
await page.goto('https://www.qikegu.com');
// await browser.close();
})();
I thinktoPromise()
should support Promise<Void>
imo Void
shouldn't be used as type parameter at all
well,close this issue now.
js code
and haxe code
@await page.emulate(d).toSurprise();
or
@await page.emulate(d).toPromise();
will got Variables of type Void are not allowed