Used to build
Evt<unknown>
event triggerinterface DomActivity {
readonly $d: Document;
open(): void;
close(): void;
waitForClose(): Promise<void>;
$appendDomToBody(ele: HTMLElement): void;
closeAble: boolean;
background: string;
titleText: string;
titleHeight: number;
titleVisible: boolean;
}
namespace DomActivity {
interface Ctor<A extends DomActivity = DomActivity> {
$d: Document;
new (name: string): A;
prototype: A;
}
interface ActivityLifeCycle<A extends DomActivity = DomActivity> {
onInit(activity: A): void;
afterInited(activity: A): void;
}
}
declare namespace BFS.Lib {
interface WebviewActivity extends DomActivity {
readonly devicePixelRatio: number;
src: string;
width: number;
height: number;
postMessage(data: unknown): void;
onMessage: Evt<unknown>;
evalJavascript(code: string): void;
onLoaded: Evt<Window>;
}
type WebviewActivityCtor = DomActivity.Ctor<WebviewActivity>;
}
import "@bfs/bfchain-runtime-typings";
const {createActivity} = bfsprocess.import('@bfs/lib-dom-activity');
const libWebview = bfsprocess.import("@bfs/lib-webview-activity");
// Create a page instance
const mainAc = createActivity("v3", libWebview.WebViewActivity);
// Set the background color of the page
mainAc.background = "red";
// Set whether the title is visible
mainAc.titleVisible = true;
// Set whether the page can be closed
mainAc.closeAble = false;
// open the page
mainAc.open();
// Set page URL
mainAc.src = "http://localhost:8100";
// Set the page title
mainAc.titleText = "This is a custom title";
// code injection
mainAc.evalJavascript(`console.log("This is the injected code")`)
// Close the page after 5s
setTimeout(()=>{
mainAc.close()
}, 5000)