Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

1.7 KB
Raw Blame
<!DOCTYPE html>
<html>
<head>
<title>WebMCP executeTool with Target Navigation</title>
<link rel="author" href="mailto:[email protected]">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="resources/helpers.js"></script>
</head>
<body>
<script>
const host_info = get_host_info();

promise_test(async t => {
  const iframe = document.createElement('iframe');
  iframe.src = 'resources/iframe-register-tool.html';
  iframe.allow = 'tools *';

  const load_promise = new Promise(resolve => iframe.onload = resolve);
  document.body.appendChild(iframe);
  t.add_cleanup(() => iframe.remove());
  await load_promise;

  // Tell iframe to register a tool.
  iframe.contentWindow.postMessage({
    action: 'register',
    hangsForever: true,
    tool: {
      name: 'iframe_tool',
      description: 'Iframe tool'
    }
  }, '*');

  // Wait for toolchange.
  await new Promise(resolve => {
    document.modelContext.addEventListener('toolchange', resolve, {once: true});
  });

  // Invoke tool and immediately navigate iframe away.
  const tools = await document.modelContext.getTools();
  const tool = tools.find(t => t.name === 'iframe_tool');
  const promise = document.modelContext.executeTool(tool);
  iframe.src = 'about:blank';

  // The promise should be rejected because the target document died.
  // We expect AbortError or similar. Let's assume AbortError for now.
  await promise_rejects_dom(t, 'UnknownError', promise, 'Promise should be rejected when target document dies');
}, 'executeTool() rejects when target document navigates away');
</script>
</body>
</html>