Is it possible to emulate orientation in a browser?

Google ChromeCssFirebugMedia QueriesDeveloper Tools

Google Chrome Problem Overview


As the title is it possible to emulate orientation in google chrome or firefox? Meaning somehow change the browser to support media query (orientation = (landscape or portrait))

I have a emulator for mobile, but I would like to have the developer tools from chrome or firebug.

Update

Chrome v25 specific...

To anyone, in Google Chrome Dev Tool > Overrides > Override Device Orientation you can change the alpha, beta and gamma. I think this is a place to start of from, but I have no idea how these work and can therefor not find anything..

It is also possible to Emulate CSS Media, but not portrait and landscape, but print, screen, tv etc.

Update v2

This is a old question, and Chrome have changed multiple times how to do this.

Google Chrome Solutions


Solution 1 - Google Chrome

In Chrome Dev Tools: If you go to Settings>Overrides>Device metrics

If you swap the dimensions for the screen resolution the orientation will change and the orientationchange-event will be triggered.

The orientation is depending on the relationship between 'width' and 'height'. If 'height' has a higher value than 'width', the browser will be in orientation: 'portrait' and vice versa.

height > width = portrait
height < width = landscape

Solution 2 - Google Chrome

I'm sure others have figured out how to emulate orientation in Chrome by now, but I came across this post and wanted to add instructions for anyone still looking for help.

It's actually rather simple.

These instructions are current as of


Chrome Stable 34.0.1847.131


From within Chrome Dev Tools (Inside Chrome, hit F12 to bring up Chrome Dev Tools) go to the Emulation tab.
Select the device you wish to emulate from the dropdownlist and hit Emulate. When you Emulate, the "Screen" section that is in the stacked section list to the left of the Emulation tab gains a checkmark to indicate it is active. Select it.

In the Screen section, the resolution of the device you are emulating will be displayed in text input fields near the top. There is a "swap dimensions" button between them that will switch the width with the height, which in essence will switch your emulation from portrait to landscape.

Some other relevant things you can do inside Chrome Dev Tools' Emulator

You can:

  • Emulate the Device pixel ratio
  • Emulate CSS media types (braille,embossed,handheld,print,projection,screen,speech,tty,tv: See RFC 2534 and related documents for more specifics)
  • Spoof user agent: you can have Chrome "impersonate" other browser engines.
  • Emulate touch screen (It's not perfect, but it's a nice touch(<=rimshot))
  • Emulate geolocation coordinates (including "position unavailable" emulation)
  • Emulate Accelerometer

My Personal Tip for Development in Portrait Orientation

Assuming you have a 16:9 monitor, a rotating VESA stand, and drivers that support a change in orientation (you can find that out in Windows' Screen Resolution settings. If there's an "Orientation" dropdownlist, then you can rotate your view)

Physically rotate your screen, then rotate your display in Windows (you can also [Ctrl][Alt][Left Arrow] to rotate the display). Emulate a portrait orientation as I mentioned above and set the Device pixel ratio to 1. This will scale up your mobile device emulator to full screen size. It won't natively trigger a mobile layout without some additional help, but em based media queries will allow you to [Ctrl][+] to scale up Chrome's em value to trigger your mobile layout.

Using the Dev Tools emulation allows you to approximate a touch screen interface without a touch screen monitor.

It also allows you to have any sized 16:9 monitor display a "widescreen" mobile layout. Naturally, a 16:10 monitor would allow you to emulate 10:16 layouts without having to resize your browser

The one feature I really want to see Google add to this is the ability while emulating to have a "double tap" auto-resize the window. That's not currently supported.

Solution 3 - Google Chrome

I am using the Console and input this line

window.dispatchEvent(new Event('orientationchange')); 

it will fire the orientationchange event and therefore trigger any event listeners that you have in your script.

Solution 4 - Google Chrome

Refer to K. Alan Bates's answer for an explanation of Chrome's more recent emulation features/updates.

https://stackoverflow.com/questions/14236245/is-it-possible-to-emulate-orientation-in-a-browser/22585680#22585680





Emulating Media Types

Open the Chrome Web Tools Panel (F12 or however you open it) Click the little sprocket in the top right of the developer tools window (bottom right in previous versions of chrome's) corner. Under the Settings heading, click Overrides. Next, mark the checkbox next to Emulate CSS Media and then select which media target you'd like to simulate from the dropdown.

enter image description here

Emulating Orientation Changes

Take a peek at http://jsfiddle.net/CoryDanielson/CuQCB/">this jsfiddle and resize the output frame -- it will switch backgrounds depending on what the browser orientation is.

body {
    background-position: top center;
}

@media screen and (orientation: portrait) {
    body { background-image: url('http://petapixel.com/assets/uploads/2013/01/vangough.jpg'); }
}
@media screen and (orientation: landscape) {
    body { background-image: url('http://cdn-media.hollywood.com/images/l/BobRoss2_620_102912.jpg'); }
}

Solution 5 - Google Chrome

As @MrOggy85 has stated you the orientation is defined by the height and width of the browser. You can emulate this in firefox via Tools > Web Developer > Responsive Design View, this lets you select common screen sizes and lets you flip the orientation. I hope this helps?

Solution 6 - Google Chrome

For the latest Chrome (version 62), it is changed completely.

  1. Toggle Developer Tools.
  2. Click the top right menu "Customize and control DevTools".
  3. Go through More tools -> Sensors.
  4. Change Orientation to Landscape left or Landscape right as u like.

Solution 7 - Google Chrome

There are a lot of answers here, but I think Chrome may have evolved slightly and this isn't too complex. Go into Developer Tools > Emulation in Chrome. There are 4 sub-tabs: Device, Screen, User Agent, and Sensors. Under Device you can choose your device (e.g. "Apple iPad 1 / 2 / Apple Mini"). If you need to simulate swapping orientation, just go into the Screen subtab and there's a little button with arrows going left and right to swap orientation. Just press that button.

Solution 8 - Google Chrome

Easy!!! default view is Portrait if you are emulating the device, (despite the css media query of portrait) you can just handle the resolutions, there's this image in Google's documentation https://developer.chrome.com/devtools/docs/mobile-emulation/device_metrics.png

Just click in the Arrows between the RESOLUTION Width and Height and its DONE!!

Enjoy

Solution 9 - Google Chrome

Device Orientation changes can be emulated in Chrome. Simply go to the "Settings" menu, which can be opened using the cog icon at the bottom right of the Developer Tools and select the "Overrides" tab. Select the "Override Device Orientation" checkbox and enter new values in to the input boxes.

Alpha represents the motion of the device around the z axis from 0 to 360 degrees. Beta represents the motion of the device around the x axis from -180 to 180 degrees - a front to back motion. Gamma represents the motion of the device around the y axis from -90 to 90 - a left to right motion. Changing the values will trigger a deviceorientation event.

Hope this is helpful.

Solution 10 - Google Chrome

In the emulation tab just click on screen button on the left and on the button between 320 and 568 so you switch the resolutions! that will emulate portrait and landscape mode.

Solution 11 - Google Chrome

Bit late but this works on Google chrome too.

Open firebug and click on the phone icon following which you can select the device model you want to see the app in.

Something like this

enter image description here

Next, go to resolution under emulation properties as shown in the picture above. (Right bottom corner) Now click on the double arrow icon in the same resolution property. You should see something like this

enter image description here

See the height and width have been swapped and hence rotated :)

Hope that helps.

Solution 12 - Google Chrome

Just change the context before setting the orientation....

driver.context("NATIVE_APP");
driver.rotate(ScreenOrientation.LANDSCAPE);
driver.context("WEBVIEW_1");

Solution 13 - Google Chrome

Toggling orientation should be available on the chrome devtools device toolbar, make sure the toolbar is wide enough or the button will be hidden! rotate button

Alternatively you can set the dimensions to reponsive and resize by dragging the corner and making it wider than it is tall. enter image description here

The device toolbar can be toggled from the run command in devtools or via hotkey (ctrl+shift+M in win)

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTryingToImproveView Question on Stackoverflow
Solution 1 - Google ChromeオスカーView Answer on Stackoverflow
Solution 2 - Google ChromeK. Alan BatesView Answer on Stackoverflow
Solution 3 - Google ChromeAndy SchmidtView Answer on Stackoverflow
Solution 4 - Google ChromeCory DanielsonView Answer on Stackoverflow
Solution 5 - Google ChromeTom RileyView Answer on Stackoverflow
Solution 6 - Google ChromeDavid ZhangView Answer on Stackoverflow
Solution 7 - Google ChromesnibbeView Answer on Stackoverflow
Solution 8 - Google Chromej.fernando.goView Answer on Stackoverflow
Solution 9 - Google ChromealdoView Answer on Stackoverflow
Solution 10 - Google ChromeRoboneterView Answer on Stackoverflow
Solution 11 - Google ChromePramod SolankyView Answer on Stackoverflow
Solution 12 - Google ChromeMayank KumawatView Answer on Stackoverflow
Solution 13 - Google ChromedogView Answer on Stackoverflow