setZoom
Category: Browser Control
Namespace: web.browser.setZoom
Description
Set the browser zoom level. Changes the page magnification (1.0 = 100%, 1.5 = 150%, 0.5 = 50%).
Syntax
await web.browser.setZoom(zoomFactor: number);
Parameters
- zoomFactor (required) - Zoom factor (1.0 = 100%, 1.5 = 150%, etc.)
Returns
Promise<boolean> - Returns true when operation completes
Example
Simple example
await web.browser.setZoom(1.5); // 150%
Practical example
document.getElementById('zoom-in').addEventListener('click', async () => {
const current = await web.browser.getZoom();
await web.browser.setZoom(current + 0.1);
});
Advanced example
async function adjustZoom(direction) {
const current = await web.browser.getZoom();
let newZoom = current;
if (direction === 'in') {
newZoom = Math.min(current + 0.1, 3.0); // Max 300%
} else if (direction === 'out') {
newZoom = Math.max(current - 0.1, 0.5); // Min 50%
} else if (direction === 'reset') {
newZoom = 1.0; // 100%
}
await web.browser.setZoom(newZoom);
const percent = Math.round(newZoom * 100);
console.log('Zoom set to:', percent + '%');
}
Use Cases
- Implement zoom in/out buttons
- Adjust page magnification
- Improve readability
- Accessibility features
- Implement zoom controls
- Keyboard shortcuts (Ctrl+/Ctrl-)
- Reset zoom to 100%
- Custom zoom levels
Related Methods
web.browser.getZoom()
Notes
- Part of browser control functionality
- Asynchronous operation
- Returns promise