Посмотри как оборнута им ChakraCore.
Да, нужно указать путь к заголовоному файлу где описаны экспортируемые функции, либа парсит файл и генерирует импорты.
Я думаю правильный ответ на сабж - никак Бесплатно поиметь гугл не получится. Нужно идти брать ключик, прописывать его и будет работать в CefSharp. Я пытался:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using CefSharp;
using CefSharp.WinForms;
namespace CefCallAPITest
{
static class Program
{
/// <summary>
/// Главная точка входа для приложения.
/// </summary>
[STAThread]
static void Main()
{
var settings = new CefSettings();
settings.CefCommandLineArgs.Add("enable-speech-input","1");
Cef.Initialize(settings);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Cef.Shutdown();
}
}
}
Форма:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CefSharp;
namespace CefCallAPITest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnCallSomeAPI_Click(object sender, EventArgs e)
{
Task<JavascriptResponse> response = chrome.EvaluateScriptAsync(scriptBox.Text);
response.Wait();
if (response.Result.Success)
{
dynamic res = response.Result.Result;
scriptBoxOut.Text = Convert.ToString(res);
} else
{
scriptBoxOut.Text = "Error: "+response.Result.Message;
}
}
private void btnGoogle_Click(object sender, EventArgs e)
{
chrome.Load("http://127.0.0.1:1646/");
}
}
}
Форма-код:
namespace CefCallAPITest
{
partial class Form1
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором форм Windows
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
this.gbBrowser = new System.Windows.Forms.GroupBox();
this.chrome = new CefSharp.WinForms.ChromiumWebBrowser();
this.btnGoogle = new System.Windows.Forms.Button();
this.btnCallSomeAPI = new System.Windows.Forms.Button();
this.scriptBox = new System.Windows.Forms.TextBox();
this.scriptBoxOut = new System.Windows.Forms.TextBox();
this.editUrl = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.gbBrowser.SuspendLayout();
this.SuspendLayout();
//
// gbBrowser
//
this.gbBrowser.Controls.Add(this.chrome);
this.gbBrowser.Dock = System.Windows.Forms.DockStyle.Top;
this.gbBrowser.Location = new System.Drawing.Point(0, 0);
this.gbBrowser.Name = "gbBrowser";
this.gbBrowser.Size = new System.Drawing.Size(800, 235);
this.gbBrowser.TabIndex = 0;
this.gbBrowser.TabStop = false;
this.gbBrowser.Text = "Browser";
//
// chrome
//
this.chrome.ActivateBrowserOnCreation = false;
this.chrome.Dock = System.Windows.Forms.DockStyle.Fill;
this.chrome.Location = new System.Drawing.Point(3, 18);
this.chrome.Name = "chrome";
this.chrome.Size = new System.Drawing.Size(794, 214);
this.chrome.TabIndex = 0;
//
// btnGoogle
//
this.btnGoogle.Location = new System.Drawing.Point(688, 241);
this.btnGoogle.Name = "btnGoogle";
this.btnGoogle.Size = new System.Drawing.Size(112, 29);
this.btnGoogle.TabIndex = 1;
this.btnGoogle.Text = "Lest\'s ROCK!";
this.btnGoogle.UseVisualStyleBackColor = true;
this.btnGoogle.Click += new System.EventHandler(this.btnGoogle_Click);
//
// btnCallSomeAPI
//
this.btnCallSomeAPI.Location = new System.Drawing.Point(688, 409);
this.btnCallSomeAPI.Name = "btnCallSomeAPI";
this.btnCallSomeAPI.Size = new System.Drawing.Size(100, 29);
this.btnCallSomeAPI.TabIndex = 2;
this.btnCallSomeAPI.Text = "Run JS";
this.btnCallSomeAPI.UseVisualStyleBackColor = true;
this.btnCallSomeAPI.Click += new System.EventHandler(this.btnCallSomeAPI_Click);
//
// scriptBox
//
this.scriptBox.Location = new System.Drawing.Point(12, 289);
this.scriptBox.Multiline = true;
this.scriptBox.Name = "scriptBox";
this.scriptBox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.scriptBox.Size = new System.Drawing.Size(776, 114);
this.scriptBox.TabIndex = 3;
//
// scriptBoxOut
//
this.scriptBoxOut.Enabled = false;
this.scriptBoxOut.Location = new System.Drawing.Point(15, 416);
this.scriptBoxOut.Name = "scriptBoxOut";
this.scriptBoxOut.Size = new System.Drawing.Size(667, 22);
this.scriptBoxOut.TabIndex = 4;
//
// editUrl
//
this.editUrl.Location = new System.Drawing.Point(12, 244);
this.editUrl.Name = "editUrl";
this.editUrl.Size = new System.Drawing.Size(670, 22);
this.editUrl.TabIndex = 5;
this.editUrl.Text = "http://127.0.0.1:1646/";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 269);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(109, 17);
this.label1.TabIndex = 6;
this.label1.Text = "JS code to eval:";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.label1);
this.Controls.Add(this.editUrl);
this.Controls.Add(this.scriptBoxOut);
this.Controls.Add(this.scriptBox);
this.Controls.Add(this.btnCallSomeAPI);
this.Controls.Add(this.btnGoogle);
this.Controls.Add(this.gbBrowser);
this.Name = "Form1";
this.Text = "Form1";
this.gbBrowser.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.GroupBox gbBrowser;
private CefSharp.WinForms.ChromiumWebBrowser chrome;
private System.Windows.Forms.Button btnGoogle;
private System.Windows.Forms.Button btnCallSomeAPI;
private System.Windows.Forms.TextBox scriptBox;
private System.Windows.Forms.TextBox scriptBoxOut;
private System.Windows.Forms.TextBox editUrl;
private System.Windows.Forms.Label label1;
}
}
Собственно скрипт на вебе:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Sample</title>
alert(13);
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript">
function readOutLoud(message) {
var speech = new SpeechSynthesisUtterance();
// Set the text and voice attributes.
speech.text = message;
speech.volume = 1;
speech.rate = 1;
speech.pitch = 1;
window.speechSynthesis.speak(speech);
}
function speakit() {
readOutLoud(document.getElementById('text').value);
};
</script>
</head>
<body>
<label for="#text">text to speak:</label>
<input type="text" id="text"/>
<br/>
<button onclick="speakit()">speak it!</button>
</body>
</html>