navigate
Category: Browser Control
Namespace: web.browser.navigate
Description
Navigate the browser to a specified URL. This loads a new page in the application's browser window, replacing the current content.
Syntax
await web.browser.navigate(url);
Parameters
- url (required) - The URL to navigate to (string)
Returns
Promise<boolean> - Returns true when navigation starts
Example
Simple example
await web.browser.navigate('https://example.com');
Practical example
const url = document.getElementById('url-input').value;
if (url) {
await web.browser.navigate(url);
}
Advanced example
async function navigateWithValidation(url) {
// Add protocol if missing
if (!url.startsWith('http://') && !url.startsWith('https://')) {
url = 'https://' + url;
}
try {
await web.browser.navigate(url);
console.log('Navigated to:', url);
} catch (error) {
console.error('Navigation failed:', error);
alert('Failed to navigate to URL');
}
}
Use Cases
- Load web pages in the application
- Navigate to different URLs based on user input
- Implement address bar functionality
- Load local HTML files
- Navigate to application pages
- Implement browser-like navigation
- Load external websites
- Navigate to file:// URLs
Related Methods
web.browser.back()- Go back in historyweb.browser.forward()- Go forward in historyweb.browser.reload()- Reload current pageweb.browser.getCurrentUrl()- Get current URL
Notes
- Supports http://, https://, and file:// protocols
- Navigation is asynchronous
- Current page is replaced
- Adds to browser history