Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macOS][iOS] window.print() JS function doesn't work with StageWebView #214

Open
itlancer opened this issue Jan 28, 2020 · 1 comment
Open

Comments

@itlancer
Copy link

Problem Description

window.print() JavaScript function doesn't work with StageWebView loaded web pages. It do nothing.

It has been tested with multiple AIR versions even with latests AIR 32.0.0.89, AIR 32.0.0.144, AIR 33.0.2.338 and AIR 33.1.0.16 beta with many macOS and iOS devices. It doesn't matter if you use URL link or HTML code provided by String with StageWebView.
Same problem in all cases.
The same works fine with system browsers with the same devices.

It doesn't work with StageWebView(true), StageWebView(false) and HTMLLoader.
But it works fine with Windows using StageWebView(true).

Also it doesn't work with Android but there are some OS limitations (https://stackoverflow.com/questions/26684190/using-window-print-or-alternative-on-android-devices). It could be usefull if we could grab BitmapData of all page (not just viewPort screenshot) to use it to print via native extension or another way.
window.print() behavior should be available to override by AIR because if it will be uncontrollable it could provide security vulnerability for kiosks (and other such solutions) where no system dialog windows allowed.

Steps to Reproduce

Launch code below with macOS or iOS device and click to "Print" button in loaded web page inside StageWebView. "Print" button make window.print() JavaScript call.

Application example with sources attached.
stagewebview_print_bug.zip

package {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.media.StageWebView;
	import flash.geom.Rectangle;
	import flash.events.ErrorEvent;
	
	public class StageWebViewPrintBug extends Sprite {
		
		public function StageWebViewPrintBug() {
			addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			var stageWebView:StageWebView = new StageWebView(true);
			stageWebView.stage = stage;
			stageWebView.viewPort = new Rectangle(0, 0, 640, 480);
			stageWebView.addEventListener(ErrorEvent.ERROR, errorOccured);
			
			var htmlCode:String = '<!DOCTYPE html>'
						+ '<html>'
						+ '<body>'
						+ '<button onclick="myFunction()">Print</button>'
						+ '<script>'
						+ 'function myFunction() {'
						+ '  window.print();'
						+ '}'
						+ '</script>'
						+ '</body>'
						+ '</html>';
			stageWebView.loadString(htmlCode);
			
			//Also you can test the same with URL
			//stageWebView.loadURL("https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_print");
		}
		
		private function errorOccured(e:ErrorEvent):void {
			trace("error", e.errorID, e.text);//No such errors occured
		}
	}
}

Actual Result:
Nothing happens.

Expected Result:
Print dialog will be provided to choose printer like with Windows.

Known Workarounds

none

  • In some cases you can use HTMLLoader with overriding JS window.print() and JS->AS3 communication using https://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118666ade46-7ed5.html but HTMLLoader doesn't support latests HTML5/CSS3 standards. Also you can only get HTMLLoader viewport screenshot to use it with PrintJob.
  • Print (via PrintJob) viewPort screenshot which captured by StageWebView::drawViewPortToBitmapData() or drawn from HTMLLoader. You need separate button out from webview. So technically you also cannot get full screenshot and initiate print from web page.
  • Write native extension with webview imlementation.
@tuarua
Copy link

tuarua commented Jan 28, 2020

FYI
macOS print functionality has been (famously) broken in WKWebView for several years and despite bug reports it looks like there is no sign of Apple fixing it any time soon.

https://forums.developer.apple.com/thread/78354

Legacy WebView is now obsoleted so is not permitted to be used (ie app will be rejected from AppStore).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants