WebView being moved to Native Extension

#1

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!

21 Likes

Defold 1.2.146 has been released
#2

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

#3

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

#4

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

#5

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?

0 Likes

#6

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.

0 Likes

#7

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?

0 Likes

#8

and dragging all the files into Defold.

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

0 Likes

#9

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>
0 Likes

#11

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.

4 Likes

#12

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

#13

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