I need to check the view source of the page from mobile / tablet browsers ( Android Phones/Tablets and Feature Phones).
I tried some of the methods but is not feasible like in desktop. I feels difficult to check it.
JS
javascript: alert(document.getElementsByTagName('html')[0].innerHTML);
Chrome && Firefox (Android)
view-source:http://domain.com
Is it there any other method to check in other browsers and in featured phone browsers
You could try the remote debugging on Chrome for desktop to debug the code on Chrome for Android
https://developer.chrome.com/devtools/docs/remote-debugging
There are several apps on Google Play that enables view source directly from the phone. Here is one: https://play.google.com/store/apps/details?id=com.androidyou.webpagelite&hl=en
A quick search on Google Play lists multiple apps: https://play.google.com/store/search?q=view%20source&c=apps&hl=en
You can try this cool app available in play store called Html Page Source https://play.google.com/store/apps/details?id=com.scintillar.hps
This is an old post but still a problem within the Chrome dev tools. I find the best way to check mobile source locally is to open the site locally in Xcode's iOS Simulator. Then from there you open the Safari browser and enable dev tools, if you have not already done this (go to preferences -> advanced -> show develop menu in menu bar). Now you will see the develop option in the main menu and can go to develop -> iOS Simulator -> and the page you have open in Xcode's iOS Simulator will be there. Once you click on it, it will open the web inspector and you can edit as you would normally in the browser dev tools.
I'm afraid this solution will only work on a Mac though as it uses Xcode.
The view-source url prefix trick didn't work for me using chrome on an iphone. There are apps I could have installed to do this I guess but for whatever reason I just preferred to do it myself rather than install 'yet another app'.
I found this nice quick tutorial for how to setup a bookmark on mobile safari that will automatically open the view source of a page: https://appletoolbox.com/2014/03/how-to-view-webpage-html-source-codes-on-ipad-iphone-no-app-required/
It worked flawlessly for me and now I have it set as a permanent bookmark any time I want, with no app installed.
Edit: There are basically 6 steps which should work for either Chrome or Safari. Instructions for Safari are:
- Open Safari and browse to an arbitrary page.
- Select the "Share" (or action") button in Safari (looks like a square with an arrow coming out of the top).
- Select "Add Bookmark"
- Delete the page title and replace it with something useful like "Show Page Source". Click Save.
- Next browse to this exact Stack Overflow answer on your phone and copy the javascript code below to your phone clipboard (code credit: Rob Flaherty):
javascript:(function(){var a=window.open('about:blank').document;a.write('<!DOCTYPE html><html><head><title>Source of '+location.href+'</title><meta name="viewport" content="width=device-width" /></head><body></body></html>');a.close();var b=a.body.appendChild(a.createElement('pre'));b.style.overflow='auto';b.style.whiteSpace='pre-wrap';b.appendChild(a.createTextNode(document.documentElement.innerHTML))})();
- Open the "Bookmarks" in Safari and opt to Edit the newly created Show Page Source bookmark. Delete whatever was previously saved in the Address field and instead paste in the Javascript code. Save it.
- (Optional) Profit!
This question is a few years old, and there are some good suggestions for workarounds, but I didn't really notice any answers that address the core of the original question head-on. So:
Providing a "universal" method for viewing source in a feature phone browser (or even arbitrary third-party smartphone browser) is impossible because "view source" — via any method — is a feature implemented in the browser. So how it's accessed, or even if it can be accessed, is up to the developers of the browser. I'm sure there are plenty of browsers that intentionally prevent the user from viewing page source, and if so then you're out of luck, except maybe for workarounds like the ones offered here.
Workarounds such as "view source" apps external to the browser, while useful in some cases, are at best an imperfect partial solution to the original request. It's never certain that any such app will display the source of the page in the same form as it's loaded by the phone's browser.
Modern web content changes itself in all manner of ways through browser detection, session management, etc. so that the source loaded by any external app can never be relied on to represent the source as loaded by a different app. If you're going to use an external app to load a page because you want to see the source, you might as well just use Chrome (or, on an iOS device, Safari) instead.
来源:https://stackoverflow.com/questions/24905940/how-to-check-view-source-in-mobile-browsers-both-android-feature-phone