The Visitor API allows you to customize the visitor side behavior of Cobrowse.
GLANCE_COBROWSE
You can control Cobrowse parameters by setting properties on the JavaScript object window.GLANCE_COBROWSE.
GLANCE_COBROWSE must be defined before the Glance cobrowse script initializes. Properties
The following properties can be set on GLANCE_COBROWSE. These properties, apart from getMaskingDescriptor, would typically be set if the visitor is logged in and the information is known at the time the page is rendered. Any or all these properties may be set.
| Property/Method | Description |
|---|---|
email | Visitor's email address. Up to 127 Latin-1 (ISO/IEC 8859-1) characters. |
getMaskingDescriptor() | Should return a promise that resolves to a masking descriptor with properties to customize page and element masking during a cobrowse session. See Using getMaskingDescriptor(). |
name | Visitor's name. Up to 63 Unicode characters. |
phone | Visitor's phone number. Up to 31 Latin-1 (ISO/IEC 8859-1) characters. |
visitorid | A user ID or string that uniquely identifies the visitor. If defined prior to the session starting, the visitorid will be used as the session key by default. It must adhere to the same requirements as a session key (see Using startSession). If using this to establish a presence connection, it must be defined before the script initializes. |
If name, email, and phone number are defined prior to the cobrowse script initializing, those values are stored with that session participant's record in the Glance database once the session starts.
Example
GLANCE_COBROWSE = {
visitorid: "59204gh-42",
name: "Joe Smith",
email: "jsmith@example.com",
phone: "314-555-1212"
};
GLANCE.Cobrowse.Visitor
The GLANCE.Cobrowse.Visitor object is defined in any web page that includes the Glance Cobrowse script tag. Sample code which implements a Cobrowse user interface using GLANCE.Cobrowse.Visitor can be found here.
Properties and Methods
The following properties and methods are available on GLANCE.Cobrowse.Visitor. (Methods marked with an asterisk * can only be called when there is an active session).
| Property/Method | Description |
|---|---|
addEventListener(eventName, listener) | Adds a listener function to be called when the specified event occurs. See Visitor Side Events. |
addSessionMessageListener(msgName, handler)* | Adds a handler function called when a message (msgName) is received from an agent. Format: function(msgName, msg) {...} where msg is the payload. |
continueSessionAt(params) | Deprecated. See Using crossDomain. |
crossDomain(options)* | Sends session info to domains in the trust list, optionally navigating to a cross-domain URL. See Using crossDomain. |
enableRC([true|false])* | Enables or disables remote control. |
getCallId()* | Returns the Call ID (unique identifier) of the active session. |
getKey()* | Returns the session key. |
getCookieValue() setCookieValue() | Convenience methods for storing UI state on the domain session cookie for faster rendering. Only available after the sessioncontinue event. |
getSessionState(eventName [, id])* | Returns info reported in the most recent state event. E.g., getSessionState("agents") returns the agent object. Returns null if the event hasn't occurred. |
getUserState(name)* setUserState(name, data)* | Stores/retrieves user state data on the server instead of a cookie. Only available after the statereceived event when navigating. |
inSession() | Returns true if a session is active. |
isMobileDevice() | Returns true if the visitor is on a mobile device. |
isPageMasked() | Returns true if the page is currently masked. |
isSessionPaused()* | Returns true if the session is currently paused. |
isRandomKey()* | Returns true if the session key was randomly generated by Glance. |
notifyChanged(params) | Notifies the script of changes to <canvas> elements. See Using notifyChanged. |
pauseSession(params)* | Indicates whether the session should be paused/unpaused. See Using pauseSession. |
readyState | Indicates the connection state: sessionend, sessionstarting, sessionstart, sessioncontinue, statereceived. |
removeEventListener(eventName, listener) | Removes the specified event listener function. |
sendDocument(file) | Allows visitors and agents to download shared documents. |
sendSessionMessage(msgName, msg)* | Sends a message with a custom name and payload to the agent. |
setUIReady() | If implementing a custom UI, call GLANCE.Cobrowse.Loader.setUIReady() once all event listeners are added. |
startSession(sessionKey|options) | Starts a session. See Using startSession(). |
stopSession()* | Stops the Cobrowse session. |
showTerms() | Deprecated. Use showTerms available on the VisitorUI API instead. |
setStartParams(options) | Sets start parameters in advance using the same options object as startSession. Call with no arguments to clear parameters. |
toggleVideo() | Toggles video on/paused. Only available if multiparticipant video has started. |
toggleVideoSize() | Toggles video size between small and large. |
viewPDF(params) | Opens a PDF using the Glance Cobrowse PDF Viewer. |
viewXLS(params) | Opens an Excel file overlaid on the screen. params = {url: "https://....xlsx"} |
Using GLANCE.Cobrowse.Visitor methods
Using startSession()
startSession() starts a Cobrowse session. You may use it in one of two ways:
startSession(key)uses a specific string key for the new session. Keys can be up to 100 characters (letters, numbers,_,-,~). If you pass"GLANCE_KEYTYPE_RANDOM", a random key is generated.startSession(options)starts a session using a configuration object.
The options object may contain:
groupid: (Optional) ID of the Glance group. Defaults to thedata-groupidin the script tag.sessionKey: (Optional) The session key.name,email,phone: Visitor details.
If starting with video (and the agent has multiparticipant privileges), you can include:
video:"large","small","off"videosource: Device ID of the camerapreviewelementid: ID of video preview element (defaults toglance_videopreview)camerastatus:"blocked","nocamera","available","error"videopaused:trueto start paused,falseto start active.
Examples
// Start with a specific key
GLANCE.Cobrowse.Visitor.startSession("ABCD");
// Start with a random key
GLANCE.Cobrowse.Visitor.startSession("GLANCE_KEYTYPE_RANDOM");
// Start in large video mode
GLANCE.Cobrowse.Visitor.startSession({ video: 'large' });
// Start with multiple parameters
var options = {
sessionKey: "ABCD",
name: "Julie Smith",
email: "jsmith@example.com",
phone: "314-555-1212"
};
GLANCE.Cobrowse.Visitor.startSession(options);
Using crossDomain()
See Cobrowse Cross-Domain for complete details.
crossDomain(options) sends session information to domains in your Cross Domain trust list. It returns a Promise. Because it opens a temporary pop-up window, it must be called in response to a user action (click/keystroke) to avoid pop-up blockers.
Alternatively, promptCrossDomain(options) (see VisitorUI API) prompts the user first, avoiding blocker issues entirely.
Options:
url: The URL to open.target:"_self"or"_blank".
Using pauseSession
pauseSession(params) freezes the view on the agent's side. If you want the session to start paused on load, add data-startpaused="1" to the cobrowse script tag. This prevents a race condition where the page uploads before the pause function is called.
While paused, no page updates are sent. If a message is specified, it overlays the frozen view. Navigating to a new page unpauses the session unless the new page also has data-startpaused="1". Single Page Applications (SPAs) like React can call this dynamically during view changes.
| Parameter | Description | Example |
|---|---|---|
| pause | Pause or unpause the session | true | false |
| message | Optional HTML string to display to the agent while paused. | "This session is paused." |
// Pause and show message
GLANCE.Cobrowse.Visitor.pauseSession({ pause: true, message: "This session is paused." });
// Unpause
GLANCE.Cobrowse.Visitor.pauseSession({ pause: false });
Using notifyChanged()
Browsers cannot automatically notify the script when <canvas> elements change. You must manually call notifyChanged() so graphs or drawings render correctly for the agent. The script identifies canvases using the data-gcid attribute.
Example
if (GLANCE && GLANCE.Cobrowse && GLANCE.Cobrowse.Visitor) {
var canvases = {
canvas: {
gcids: [$("#c1").attr("data-gcid"), $("#c2").attr("data-gcid")]
}
};
GLANCE.Cobrowse.Visitor.notifyChanged(canvases);
}
Using getMaskingDescriptor()
Glance provides a hook function to dynamically customize page and element masking: window.GLANCE_COBROWSE.getMaskingDescriptor(params).
This hook must be included in the page before the Glance script loads. The script calls this hook on every page navigation before sending contents to the agent. It should return a Promise resolving to a masking descriptor:
{
"maskpage": false,
"maskedelements": [".sensitive-data", "#ssn-field"]
}
The script also calls this hook (passing an agents object) whenever an agent or guest joins/leaves. If the hook returns new rules, a full update is sent to the agent.
Note: The "maskpage" property overrides the group-level Allow/Deny list, and "maskedelements" are applied in addition to any selectors configured in your Glance group settings.
If the Promise rejects, the entire page is masked for security.
Parameters passed to getMaskingDescriptor
If known, agent information is passed via { agents: [agent information] }:
{
"count": 2,
"agentlist": [
{
"username": "fred.glance.net",
"guestid": 42309845,
"partnerid": 12345,
"partneruserid": "fred@myco.com",
"name": "Fred O'Hare",
"role": "agent",
"agentrole": "Business Unit 1",
"num": 1
}
]
}
Masking Based on Web Service Example
GLANCE_COBROWSE.getMaskingDescriptor = async function () {
return new Promise(async (resolve, reject) => {
let agenttoken = Cookies.get("agenttoken");
let maskinginfo = await fetch(`/api/GetAgentMaskRules?id=${agenttoken}`);
if (!maskinginfo.ok) {
reject("Error attempting to query masking info");
} else {
let data = await maskinginfo.json();
resolve({
"maskpage": false,
"maskedelements": data.maskedelements
});
}
});
}
Role-Based Masking Example
Masking elements dynamically based on the specific agentrole of the agent in the session.
GLANCE_COBROWSE.getMaskingDescriptor = async function (params) {
return new Promise(async (resolve, reject) => {
let maskingdescriptor = {};
// If agent info isn't available yet, mask all role-specific fields
if (!params.agents || params.agents.count === 0) {
maskingdescriptor.maskedelements = ["[data-agentrole]"];
} else {
// Mask fields that do NOT match the current agent's role
let currentRole = params.agents.agentlist[0].agentrole.toLowerCase();
maskingdescriptor.maskedelements = [`[data-agentrole]:not([data-agentrole='${currentRole}'])`];
}
resolve(maskingdescriptor);
});
}