/** * Test script to verify the background URL opening functionality * This script tests the new browser setting for opening URLs in background pages */ const MCP_HTTP_URL = 'http://localhost:3001/mcp'; async function testBackgroundUrlSetting() { console.log('🧪 Testing Background URL Opening Setting...\n'); try { // Test 1: 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-url-test', version: '1.0.0', }, }, }), }); const initResult = await initResponse.json(); console.log('āœ… Initialization response:', initResult.result ? 'Success' : 'Failed'); // Test 2: Navigate without explicit backgroundPage parameter (should use setting) console.log('\n2ļøāƒ£ Testing navigation without explicit backgroundPage parameter...'); console.log(" This should use the user's browser setting preference"); const defaultNavResponse = 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', // No backgroundPage parameter - should use user setting }, }, }), }); const defaultNavResult = await defaultNavResponse.json(); console.log('āœ… Default navigation result:', JSON.stringify(defaultNavResult, null, 2)); // Test 3: Navigate with explicit backgroundPage=true (should override setting) console.log('\n3ļøāƒ£ Testing navigation with explicit backgroundPage=true...'); console.log(' This should override the user setting and open in background'); const explicitBackgroundResponse = 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', arguments: { url: 'https://www.google.com', backgroundPage: true, // Explicit override }, }, }), }); const explicitBackgroundResult = await explicitBackgroundResponse.json(); console.log( 'āœ… Explicit background navigation result:', JSON.stringify(explicitBackgroundResult, null, 2), ); // Test 4: Navigate with explicit backgroundPage=false (should override setting) console.log('\n4ļøāƒ£ Testing navigation with explicit backgroundPage=false...'); console.log(' This should override the user setting and open in foreground'); const explicitForegroundResponse = 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.github.com', backgroundPage: false, // Explicit override }, }, }), }); const explicitForegroundResult = await explicitForegroundResponse.json(); console.log( 'āœ… Explicit foreground navigation result:', JSON.stringify(explicitForegroundResult, null, 2), ); console.log('\nšŸŽ‰ All tests completed!'); console.log('\nšŸ“‹ Test Summary:'); console.log(' • Default navigation uses browser setting preference'); console.log(' • Explicit backgroundPage=true overrides setting'); console.log(' • Explicit backgroundPage=false overrides setting'); console.log('\nšŸ’” To test the setting:'); console.log(' 1. Open the Chrome extension popup'); console.log(' 2. Go to Browser Settings section'); console.log(' 3. Toggle "Open URLs in background pages by default"'); console.log(' 4. Run this test script again to see the difference'); } catch (error) { console.error('āŒ Test failed:', error); } } // Run the test testBackgroundUrlSetting();