Example
// Create an async function, so we can use the async/await commands.
async function buildWebview() {
// Wait for the Agent library to finish initialising
await window.Agent.onReadyAsync();
// Get the ID of this display
const displayId = window.Agent._acw.displayId;
// Set the ID of this window
const windowId = 'Window-' + displayId;
// Get the Webview Manager object for this Window
const WebviewManager = window.Agent.Webview.Manager[windowId];
// Define the URL we want to point the webview at
const url = 'http://www.adobe.com';
// Create a webview pointing to a URL
// this function will return and reference ID to the webview
// Additionally we need to pass in the z-index of the webview to ensure that it appears above
// the current webview (which has a z-index of 10).
// Note: Ensure the zindex and revealafterload variables are written in all lowercase as these configuration options are case sensitive.
const webviewId = await WebviewManager.create({url: url, zindex: 11, revealafterload: true});
// The webview will be created and will become visible once the page has successfully loaded.
// Once a webview has been created you can manipulate its configuration
// Using the setConfiguration method we can pass in the webview id and the relevant configuration options
// Note: This function sets the state of the webview (except the url) as per the option passed in here, remember to add config options like zindex in or default values may be used.
await WebviewManager.setConfiguration(webviewId, {top: '0', left: '50vw', width: '50vw', height: '50vh', zindex: 11});
// Tell the webview to re-render the webview with the updated configuration
await WebviewManager.draw(webviewId);
// Capture a screenshot
const dataUrl = await WebviewManager.getWebviewCapture(webviewId);
// Get all webviews
const webviews = await WebviewManager.getWebviews();
console.log(`We have ${webviews.length} webviews`);
for (const [index, webview] of webviews.entries()) {
console.log(`Webview ${index} is on url: ${webview.url}`);
}
// Close a webview
await WebviewManager.close(webviewId);
// Listen for different webview events
// Listen for a webview loading
WebviewManager.onContentLoad(webvwId => {
console.log('A webview has finished loading');
console.log(
'This webview ' +
(webvwId === webviewId)
? 'is'
: 'is not' +
' the one we created.');
});
// Listen for a webview being closed
WebviewManager.onExit(webvwId => {
console.log('A webview has been closed');
console.log(
'This webview ' +
(webvwId === webviewId)
? 'is'
: 'is not' +
' the one we created.');
})
}
//
Methods
(async) canWebviewGoBackward(id) → {Promise.<Boolean>}
Check if a webview can move backwards in history
Parameters:
Name | Type | Description |
---|---|---|
id |
UUID |
The ID of the Webview |
(async) canWebviewGoForward(id) → {Promise.<Boolean>}
Check if a webview can move forwards in history
Parameters:
Name | Type | Description |
---|---|---|
id |
UUID |
The ID of the Webview |
(async) clearData(id) → {Promise.<void>}
Request the webvew to be cleared.
Parameters:
Name | Type | Description |
---|---|---|
id |
UUID |
The ID of the Webview |
(async) create(configuration) → {Promise.<UUID>}
Create a webview with the provided configuration.
Parameters:
Name | Type | Description |
---|---|---|
configuration |
WebviewConfiguration |
(async) draw(id) → {Promise.<void>}
Request a webview to re-render itself based on the configuration it was previously provided.
Parameters:
Name | Type | Description |
---|---|---|
id |
UUID |
The ID of the Webview |
(async) getVisibleWebviews() → {Promise.<Array.<WebviewConfiguration>>}
Get the configuration of all of the existing webviews that are visible.
(async) getWebview(id) → {Promise.<WebviewConfiguration>}
Get the configuration of the webview with the provided id
Parameters:
Name | Type | Description |
---|---|---|
id |
UUID |
The ID of the webview to return the configuration of |
(async) getWebviewByUrl(url) → {Promise.<UUID>}
Find a webview based on its URL
Parameters:
Name | Type | Description |
---|---|---|
url |
String |
The URL of the webview to find |
(async) getWebviewCapture(id) → {Promise.<String>}
Get a DataURL string representing a screenshot of the provided webview
Parameters:
Name | Type | Description |
---|---|---|
id |
UUID |
The ID of the Webview |
(async) getWebviews() → {Promise.<Array.<WebviewConfiguration>>}
Get the configuration of all of the existing webviews.
(async) goBackwardWebview(id) → {Promise.<void>}
Request a webview to move Backward in history
Parameters:
Name | Type | Description |
---|---|---|
id |
UUID |
The ID of the Webview |
(async) goForwardWebview(id) → {Promise.<void>}
Request a webview to move Forward in history
Parameters:
Name | Type | Description |
---|---|---|
id |
UUID |
The ID of the Webview |
(async) kill(id, reasonopt) → {Promise.<void>}
Kill a webview.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
id |
UUID |
The ID of the Webview |
||
reason |
String |
<optional> |
"Unknown" |
The reason this webview was killed (Optional) |
onClose(callback)
Register a callback for the Close Event, this event is triggered when a page loaded in the webview requests to "close"
Parameters:
Name | Type | Description |
---|---|---|
callback |
WebviewCloseEventCallback |
Listens to Events:
- event:WebviewCloseEvent
onContentLoad(callback)
Register a callback for the Content Load Event, this event is triggered when a page loads.
Parameters:
Name | Type | Description |
---|---|---|
callback |
WebviewContentLoadEventCallback |
onDialog(callback)
Parameters:
Name | Type | Description |
---|---|---|
callback |
function |
onExit(callback)
Parameters:
Name | Type | Description |
---|---|---|
callback |
function |
onFindUpdate(callback)
Parameters:
Name | Type | Description |
---|---|---|
callback |
function |
onLoadAbort(callback)
Parameters:
Name | Type | Description |
---|---|---|
callback |
function |
onLoadCommit(callback)
Parameters:
Name | Type | Description |
---|---|---|
callback |
function |
onLoadRedirect(callback)
Parameters:
Name | Type | Description |
---|---|---|
callback |
function |
onLoadStart(callback)
Parameters:
Name | Type | Description |
---|---|---|
callback |
function |
onLoadStop(callback)
Parameters:
Name | Type | Description |
---|---|---|
callback |
function |
onNewWindow(callback)
Parameters:
Name | Type | Description |
---|---|---|
callback |
function |
onPermissionRequest(callback)
Parameters:
Name | Type | Description |
---|---|---|
callback |
function |
onRequestCompleted(callback)
Parameters:
Name | Type | Description |
---|---|---|
callback |
function |
onRequestErrorOcurred(callback)
Parameters:
Name | Type | Description |
---|---|---|
callback |
function |
onResponsive(callback)
Parameters:
Name | Type | Description |
---|---|---|
callback |
function |
onSizeChanged(callback)
Parameters:
Name | Type | Description |
---|---|---|
callback |
function |
onUnResponsive(callback)
Parameters:
Name | Type | Description |
---|---|---|
callback |
function |
onZoomChanged(callback)
Parameters:
Name | Type | Description |
---|---|---|
callback |
function |
(async) print(id) → {Promise.<void>}
Request a webview to be printed.
Parameters:
Name | Type | Description |
---|---|---|
id |
UUID |
The ID of the Webview |
(async) refresh(id) → {Promise.<void>}
Request the Webview to refresh/reload the page it is currently on.
Parameters:
Name | Type | Description |
---|---|---|
id |
UUID |
The ID of the Webview |
(async) setWebviewConfiguration(id, configuration) → {Promise.<void>}
Update the configuration of a Webview.
Using the setConfiguration method we can pass in the webview id and the relevant configuration options Note: This function sets the state of the webview (except the url) as per the option passed in here, remember to add config options like zindex in or default values may be used.
Parameters:
Name | Type | Description |
---|---|---|
id |
UUID |
The ID of the Webview |
configuration |
WebviewConfiguration |
The Configuration of the webview. |
(async) setWebviewHidden(id) → {Promise.<void>}
Request a Webview to become hidden
Parameters:
Name | Type | Description |
---|---|---|
id |
UUID |
The ID of the Webview |
(async) setWebviewVisible(id) → {Promise.<void>}
Request a Webview to become visible
Parameters:
Name | Type | Description |
---|---|---|
id |
UUID |
The ID of the Webview |