// Test script to verify background page navigation functionality // This tests the new backgroundPage parameter for chrome_navigate and chrome_navigate_natural tools console.log('๐Ÿงช Testing Background Page Navigation Functionality\n'); // Test configuration const MCP_HTTP_URL = 'http://localhost:3001/mcp'; async function testBackgroundPageNavigation() { try { console.log('๐Ÿš€ Starting background page navigation tests...\n'); // Initialize MCP connection console.log('1๏ธโƒฃ Initializing MCP connection...'); const initResponse = await fetch(MCP_HTTP_URL, { method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json', }, body: JSON.stringify({ jsonrpc: '2.0', id: 0, method: 'initialize', params: { protocolVersion: '2024-11-05', capabilities: {}, clientInfo: { name: 'background-page-test', version: '1.0.0', }, }, }), }); const initResult = await initResponse.json(); console.log('โœ… Initialization response:', initResult.result ? 'Success' : 'Failed'); // Test 1: Regular navigation with backgroundPage=true console.log('\n2๏ธโƒฃ Testing chrome_navigate with backgroundPage=true...'); const backgroundNavResponse = await fetch(MCP_HTTP_URL, { method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json', }, body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name: 'chrome_navigate', arguments: { url: 'https://www.example.com', backgroundPage: true, }, }, }), }); const backgroundNavResult = await backgroundNavResponse.json(); console.log('โœ… Background navigation result:', JSON.stringify(backgroundNavResult, null, 2)); // Test 2: Natural language navigation with backgroundPage=true console.log('\n3๏ธโƒฃ Testing chrome_navigate_natural with backgroundPage=true...'); const naturalBackgroundResponse = await fetch(MCP_HTTP_URL, { method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json', }, body: JSON.stringify({ jsonrpc: '2.0', id: 2, method: 'tools/call', params: { name: 'chrome_navigate_natural', arguments: { query: 'google', backgroundPage: true, }, }, }), }); const naturalBackgroundResult = await naturalBackgroundResponse.json(); console.log('โœ… Natural language background navigation result:', JSON.stringify(naturalBackgroundResult, null, 2)); // Test 3: Compare with regular navigation (backgroundPage=false) console.log('\n4๏ธโƒฃ Testing chrome_navigate with backgroundPage=false for comparison...'); const regularNavResponse = await fetch(MCP_HTTP_URL, { method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json', }, body: JSON.stringify({ jsonrpc: '2.0', id: 3, method: 'tools/call', params: { name: 'chrome_navigate', arguments: { url: 'https://www.google.com', backgroundPage: false, }, }, }), }); const regularNavResult = await regularNavResponse.json(); console.log('โœ… Regular navigation result:', JSON.stringify(regularNavResult, null, 2)); // Test 4: Test with both newWindow and backgroundPage (backgroundPage should take precedence) console.log('\n5๏ธโƒฃ Testing chrome_navigate with both newWindow=true and backgroundPage=true...'); const conflictTestResponse = await fetch(MCP_HTTP_URL, { method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json', }, body: JSON.stringify({ jsonrpc: '2.0', id: 4, method: 'tools/call', params: { name: 'chrome_navigate', arguments: { url: 'https://www.github.com', newWindow: true, backgroundPage: true, }, }, }), }); const conflictTestResult = await conflictTestResponse.json(); console.log('โœ… Conflict test result:', JSON.stringify(conflictTestResult, null, 2)); console.log('\nโœจ All background page navigation tests completed!'); // Summary console.log('\n๐Ÿ“Š Test Summary:'); console.log('โœ… Background page navigation with chrome_navigate tested'); console.log('โœ… Background page navigation with chrome_navigate_natural tested'); console.log('โœ… Regular navigation comparison tested'); console.log('โœ… Parameter conflict handling tested'); console.log('\n๐ŸŽฏ Expected Behavior:'); console.log('- backgroundPage=true should create a minimized window'); console.log('- backgroundPage=false should use normal tab/window behavior'); console.log('- backgroundPage should take precedence over newWindow when both are true'); console.log('- Natural language navigation should support backgroundPage parameter'); } catch (error) { console.error('โŒ Test failed:', error.message); console.error('Stack trace:', error.stack); } } // Run the tests testBackgroundPageNavigation().catch(console.error);