WebView being moved to Native Extension

With Defold release 1.2.146 we are moving the previous core module webview into an external native extension library.

If you previously were using webview , you will need to add the following URL to your dependencies in game.project :

https://github.com/defold/extension-webview/archive/master.zip

Reasoning

As presented in out roadmap for H1 2019, we are in the process of making the engine runtime more modular.

During H1-2019 we will use this system to extract non-vital parts of the engine core into native extensions, thus giving users even better control of what to include in the engine core, as well as opening up for community collaboration and improvements. We will start by extracting the webview into a native extension and then move on to also extract push, iap, iac and the Facebook SDK.

The webview module is our first step in this direction, itā€™s a good candidate for us to learn what removing modules from the core would mean for both us and our users.

Changes

Only a stub implementation is left in engine core, it will throw a Lua error if any webview function is used on mobile. The error will look like this:

webview has been removed from core, please read /builtins/docs/webview.md for more information.

Documentation

The documentation for webview is now available here: https://defold.github.io/extension-webview/

Caveats

  • The code editor inside Defold will no longer display code completion for the webview namespace. We are looking into a general solution for this, where libraries/extensions can expose code completions. However, this feature will not be available in 1.2.146 and we are sorry for the inconvenience. The issue ID for this feature is: DEFEDIT-1532

Feedback

We are open for your feedback and would like to hear any suggestions how we can make this new direction as painless as possible for our users. If you have any suggestions or annoyances how this new direction will affect you, please reply to this topic!

23 Likes

You will continue use old doc format for webview, or it will use another format? Prev was json, now you use yml, if i understand right.

EmmyLua use lua annotations(something like luadoc) to describe params,functions,types. It is very easy to use it. If in library we can use annotations in lua to make autocomple it will be cool and easy for users. https://emmylua.github.io/annotations/return.html

1 Like

We have a meeting on Thursday to discuss and hopefully agree on a format for documenting extensions so that the editor can provide autocomplete. I havenā€™t heard of EmmyLua before but Iā€™ll take a look at it for sure!

5 Likes

I think Iā€™m missing something. The goal wasnā€™t to disable webview completely, right? Just to switch from a core module to an extension.

Iā€™m using the Defold 1.2.150 with Mac OS 10.12.6 building to a Samsung Galaxy S7. I have a new project using the extension-webview URL above and dirtylarry, which both load into the project fine. I get the following error:

ERROR:SCRIPT: /main/main.gui_script:54: webview has been removed from core, please read /builtins/docs/webview.md for more information.
stack traceback:
[C]: in function 'create'

webview_available() returns true. In fact, I can pprint(webview) and get a list of functions. So, as far as I know, I am trying to use webview as an extension. What am I missing?

1 Like

Can you confirm if you download and build the example project it doesnā€™t work?

Also did you install an apk built after adding the NE to your phone?

Yes, I used the example project both by including https://github.com/defold/extension-webview/archive/master.zip as a dependency (then manually creating the script), and in a different project by downloading the zip, unzipping it, and dragging all the files into Defold. On the device, I installed the most recent version of dmengine and used that as the Target. The dirtylarry buttons show up on the device.

Can you download the example and test it just to be sure? I donā€™t mean including the NE in your own project.

By most recent version of dmengine do you mean one from d.defold.com or one you actually built which includes the NE code?

and dragging all the files into Defold.

No need to do that. Unzip and double click on game.project.

dmengine came from engine/armv7-android/dmengine.apk link from the 1.2.150 release at d.defold.com.

I downloaded https://github.com/defold/extension-webview/archive/master.zip, unzipped it and double-clicked on game.project. When defold came up, I connected to my device under Target, and chose Build. The output in the console was:

INFO:ENGINE: Defold Engine 1.2.150 (e79cdec)
INFO:ENGINE: Loading data from: http://192.168.1.27:54694/build
INFO:ENGINE: Initialised sound device 'default'

ERROR:SCRIPT: /main/main.gui_script:54: webview has been removed from core, please read 
   /builtins/docs/webview.md for more information.
     stack traceback:
    [C]: in function 'create'
    /main/main.gui_script:54: in function </main/main.gui_script:48>
ERROR:GAMESYS: Error when initializing gui component: -2.
WARNING:ENGINE: Unknown Android input method [KeyEvent], defaulting to key events

On the device, are 3 buttons (ā€œOpen www.google.comā€, ā€œShowā€, ā€œHideā€). When I hit the ā€œOpenā€ button, I get these additional lines in the console:

ERROR:SCRIPT: /main/main.gui_script:66: webview has been removed from core, please read 
/builtins/docs/webview.md for more information.
stack traceback:
    [C]: in function 'open'
    /main/main.gui_script:66: in function 'cb'
    /dirtylarry/dirtylarry.lua:67: in function 'button'
    /main/main.gui_script:63: in function </main/main.gui_script:62>

The issue is that you are running an engine without the webview components built in (the one downloaded from d.defold.com is a ā€œvanillaā€ build, without any extensions).

Itā€™s not possible to build and launch a completely different engine binary directly to the device from the editor.

The solution is to bundle your project once for Android, install that APK to your device instead. Then you will be running a binary that has webview included, so you will be able to run ā€œBuild & Launchā€ to it as a target.

5 Likes

Thanks for sticking with me. I knew I was missing something fundamental. OK. So, now I am set up building an apk and seeing debug messages with adb. When I run on the device, the webview table is nil and I get the debug message from webview_available().

I thought that maybe I had to do some manual steps outside of defold, so I tried the example https://github.com/defold/extension-android using the same process (download zip, double-click the project file, defold Bundle apk, copy apk to device, install on device, run on device (including adb over usb)). The extension-android example runs fine on the device. Iā€™ll try a few more examples and see whether I can narrow down which ones I have issues with.

I am trying to digest the Extensions Manual (https://www.defold.com/manuals/extensions/) but Iā€™m not not yet understanding how a table from an extension becomes available in the namespace of a script. There is no require so it is compiled in at some point and makes itself available to lua.

2 Likes

Exactly. Extensions declare their public Lua API in the extension init code. This usually means creating one or more tables on the Lua global table.

2 Likes

Hi all,

It seems something was wrong when I bundled to Android with the same sample project from https://github.com/defold/extension-webview. My config is: Defold - 1.2.157, MacOS Mojave

07-08 18:43:28.176 7992 8010 E defold : ERROR:SCRIPT: main/main.gui_script:66: webview has been removed from core, please read /builtins/docs/webview.md for more information.
07-08 18:43:28.176 7992 8010 E defold : stack traceback:
07-08 18:43:28.176 7992 8010 E defold : [C]: in function ā€˜openā€™
07-08 18:43:28.176 7992 8010 E defold : main/main.gui_script:66: in function ā€˜cbā€™
07-08 18:43:28.176 7992 8010 E defold : dirtylarry/dirtylarry.lua:67: in function ā€˜buttonā€™
07-08 18:43:28.176 7992 8010 E defold : main/main.gui_script:63: in function <main/main.gui_script:62>

My process: download zip, open project, Project-> Bundle->Android, copy apk to device, install, run on device with no success.

Is there any way to check the webview component has been include in apk file?

Thank you

NamNguyen

Thatā€™s strange, I just tried the same here and it works. Bundled the extension-webview project for Android and installed it (via adb)ā€¦ :thinking:

You havenā€™t done any changes to the project, or changed the build server URL preferences?

thanks sven,

I tried both: via adb and manually copy to device, my device is Asus Zenfon4, Android 8.1.0. So if it is bundled as your instructions, the reason maybe is webview could not be invoked?

After error running built with older Defold version, I make a fresh config (download Defold 1.2.157, download webview as zip, run project file, build successfully) with no modification anything, my Extensions config as follow:
45

Hi sven,

Could you please send me the app at your build?

Thank you very much!

Sent you a PM.

1 Like

Hi!
The problem is still relevant.
Defold 1.2.158
Platforms iOS, Android
When using webview, the error ā€œwebview has been removed from coreā€ crashes.
Build with

Prodject->Bundle->ios(android) application

2 Likes

I found the issue and made a PR, I think we will merge it tomorrow.

4 Likes

Merged into master, should be fine now.

3 Likes