Intoli

Intoli Remote Browser Tour

Handling Remote Errors

When dealing with code execution in remote contexts, it's important to be able to catch and handle any errors that might occur. Remote Browser has a concept of "Remote Errors" which are unhandled errors thrown in one of the remote script contexts. These errors are automatically caught and transferred back to the client context where a RemoteError is raised. This new error will have a remoteError property which is an object containing the name, message, stack information, etc. from the original error.

6/7
import Browser, { RemoteError } from 'remote
    -browser';
// Launch a remote browser instance.
const browser = new Browser();
await browser.launch();
// Let's make a mistake on purpose here, note
    the spelling of `create`.
try {
await browser.tabs.craete({ url: 'https
      ://intoli.com/blog' });
} catch (error) {
// We could handle errors differently
      depending on their type.
const isRemoteError = (error instanceof
      RemoteError);
console.log(`Is it a remote error?
      ${isRemoteError}`);
// Reraise the error after we clean up the
      browser instance.
await browser.quit();
throw error;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX