@@ -136,7 +136,11 @@ def close_connection
136
136
end
137
137
138
138
#
139
- # Overrides device screen dimensions and emulates viewport according to parameters
139
+ # Overrides device screen dimensions and emulates viewport according to parameters.
140
+ #
141
+ # Note that passing mobile: true will cause set_viewport to ignore the passed
142
+ # height and width values, and instead use 390 x 844, which is the viewport size
143
+ # of an iPhone 14.
140
144
#
141
145
# Read more [here](https://chromedevtools.github.io/devtools-protocol/tot/Emulation/#method-setDeviceMetricsOverride).
142
146
#
@@ -149,27 +153,36 @@ def close_connection
149
153
# @param [Boolean] mobile whether to emulate mobile device
150
154
#
151
155
def set_viewport ( width :, height :, scale_factor : 0 , mobile : false )
152
- command (
153
- "Emulation.setDeviceMetricsOverride" ,
154
- slowmoable : true ,
155
- width : width ,
156
- height : height ,
157
- deviceScaleFactor : scale_factor ,
158
- mobile : mobile
159
- )
160
-
161
- options = if mobile
162
- {
163
- enabled : true ,
164
- maxTouchPoints : 1
165
- }
166
- else
167
- {
168
- enabled : false
169
- }
170
- end
171
-
172
- command ( "Emulation.setTouchEmulationEnabled" , **options )
156
+ if mobile
157
+ command (
158
+ "Emulation.setTouchEmulationEnabled" ,
159
+ enabled : true ,
160
+ maxTouchPoints : 1
161
+ )
162
+
163
+ command (
164
+ "Emulation.setDeviceMetricsOverride" ,
165
+ deviceScaleFactor : 3.0 ,
166
+ height : 844 ,
167
+ mobile : true ,
168
+ slowmoable : true ,
169
+ width : 390
170
+ )
171
+ else
172
+ command (
173
+ "Emulation.setTouchEmulationEnabled" ,
174
+ enabled : false
175
+ )
176
+
177
+ command (
178
+ "Emulation.setDeviceMetricsOverride" ,
179
+ deviceScaleFactor : scale_factor ,
180
+ height : height ,
181
+ mobile : false ,
182
+ slowmoable : true ,
183
+ width : width
184
+ )
185
+ end
173
186
end
174
187
175
188
def resize ( width : nil , height : nil , fullscreen : false , mobile : false )
0 commit comments