Fix for #44 promise wait for fonts (#45)

`runtime.ExceptionDetails: Uncaught exception at 4:47: SyntaxError: Unexpected token %`
This commit is contained in:
Sergei Opletaev
2019-02-01 09:21:02 +01:00
committed by Julien Neuhart
parent e6484bb2d5
commit f9fb97a572

View File

@@ -107,10 +107,13 @@ func (html *HTML) Print(destination string) error {
document.fonts.ready.then(function () {
resolve('fonts loaded');
});
setTimeout(resolve.bind(resolve, 'timeout'), %.0f);
setTimeout(resolve.bind(resolve, 'timeout'), 500);
});`
scriptArg := runtime.NewEvaluateArgs(script).SetAwaitPromise(true)
returnObj, _ := c.Runtime.Evaluate(html.Context, scriptArg)
if returnObj.ExceptionDetails != nil {
return fmt.Errorf("script evaluated with exception: %+v", returnObj.ExceptionDetails)
}
loadFontsResult := string(returnObj.Result.Value)
if strings.Contains(loadFontsResult, "timeout") {
return errors.New("timed out loading fonts")