You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: `IMPORTANT: Emulates a mobile device including viewport, user-agent, touch support, and device scale factor. This tool MUST be called BEFORE navigating to any website to ensure the correct mobile user-agent is used. Essential for testing mobile website performance and user experience.`,
111
+
annotations: {
112
+
category: ToolCategories.EMULATION,
113
+
readOnlyHint: false,
114
+
},
115
+
schema: {
116
+
device: z
117
+
.enum(deviceOptions)
118
+
.describe(
119
+
`The device to emulate. Available devices are: ${deviceOptions.join(', ')}. Set to "No emulation" to disable device emulation and use desktop mode.`,
120
+
),
121
+
customUserAgent: z
122
+
.string()
123
+
.optional()
124
+
.describe(
125
+
'Optional custom user agent string. If provided, it will override the device\'s default user agent.',
126
+
),
127
+
},
128
+
handler: async(request,response,context)=>{
129
+
const{ device, customUserAgent }=request.params;
130
+
131
+
// get all pages to support multi-page scene
132
+
awaitcontext.createPagesSnapshot();
133
+
constallPages=context.getPages();
134
+
constcurrentPage=context.getSelectedPage();
135
+
136
+
// check if multi pages and apply to all pages
137
+
letpagesToEmulate=[currentPage];
138
+
letmultiPageMessage='';
139
+
140
+
if(allPages.length>1){
141
+
// check if other pages have navigated content (maybe new tab page)
142
+
constnavigatedPages=[];
143
+
for(constpageofallPages){
144
+
consturl=page.url();
145
+
if(url!=='about:blank'&&url!==currentPage.url()){
146
+
navigatedPages.push({ page, url });
147
+
}
148
+
}
149
+
150
+
if(navigatedPages.length>0){
151
+
// found other pages have navigated, apply device emulation to all pages
0 commit comments