MCPcopy Create free account
hub / github.com/ChromeDevTools/chrome-devtools-mcp / selectNativeSelectOption

Function selectNativeSelectOption

src/tools/input.ts:81–120  ·  view source on GitHub ↗
(
  handle: ElementHandle<Element>,
  signal: AbortSignal,
)

Source from the content-addressed store, hash-verified

79}
80
81async function selectNativeSelectOption(
82 handle: ElementHandle<Element>,
83 signal: AbortSignal,
84): Promise<boolean> {
85 using selectHandle = await handle.evaluateHandle(node => {
86 if (!(node instanceof HTMLOptionElement)) {
87 return null;
88 }
89
90 const select = node.closest('select');
91 if (!select || select.multiple || select.disabled || node.disabled) {
92 return null;
93 }
94
95 const parentElement = node.parentElement;
96 if (
97 parentElement instanceof HTMLOptGroupElement &&
98 parentElement.disabled
99 ) {
100 return null;
101 }
102
103 return select;
104 });
105
106 using select = selectHandle.asElement() as ElementHandle<Element> | null;
107 if (!select) {
108 return false;
109 }
110
111 using valueHandle = await handle.getProperty('value');
112
113 const value = await valueHandle.jsonValue();
114 if (typeof value !== 'string') {
115 return false;
116 }
117 await select.asLocator().fill(value, {signal});
118
119 return true;
120}
121
122export const click: PageToolFactory = definePageTool(() => ({
123 name: 'click',

Callers 1

input.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected