microsoft/vscode-cordova

Debug fails with [cordova-debug-adapter] Error: Unable to find webview

indy7 opened this issue · 32 comments

indy7 commented

I just updated my VSC with the latest 1.1.0 cordova-tools.
When I debug my Ionic2 project w/ Run on iOS Simulator, I keep getting the '[cordova-debug-adapter] Error: Unable to find webview'.
I am running mac OS El Capitan and XCode 7.3.
From my observation, this error occurs while it is trying to load the app in the simulator.
The thing is, even with this error the app eventually loads in the simulator.
But in VSC the debug has ended due to the error. So I have no way of getting the breakpoint to hit, etc.

How long did your app take to launch? If it takes longer than 5 seconds to start up you may need to increase the timeout in your launch.json by specifying attachAttempts or attachDelay. By default we try 5 times with a delay of 1000ms between each attempt.

Same erro "Unable to find webview", can you an example aatachDelay or/and atatchAttemps configuration?

with configuration:

{
"name": "Attach to running iOS on simulator",
"type": "cordova",
"request": "attach",
"platform": "ios",
"target": "emulator",
"port": 9222,
"sourceMaps": true,
"cwd": "${workspaceRoot}",
"attachAttempts": 5,
"attachDelay": 5000
},

Same error... Unable to find webview

Just as an FYI, I used to run into the same issue and using attachDelay and attachAttempts did resolve this for me.

iOS 9.3, latest XCode, Cordova v.5.4.1 project.

@imacnu I used the snippet you provided and it works as expected for me.

@imacnu This error can also happen if you have more than one Simulator running (for example, if several users are logged in on the same machine and each using the Simulator). If that's the case for you, you will need to fully quit all the other simulators.

If that's not it, then how long does your app take to fully launch on the simulator? Your example shows 5 attempts of 5 seconds each; maybe that's not enough? Is your app fully up and running within 25 seconds? If not, it may be worth increasing the attachDelay to a higher value to see if that helps.

Let us know how that goes, and if it didn't help we'll investigate further.

Still does not work with any delay :(

Can you please run the app in the emulator, and then after VS code gives you the error, while the app is still running go to a console and run ios_webkit_debug_proxy. You should see something like Connected to SIMULATOR on port 9223

While both the app and ios_webkit_debug_proxy are running, in another window run curl localhost:9223/json, where 9223 is whatever port the simulator is on. The response should be a list of apps running on the simulator which can be debugged, can you please include that output here and we should be able to determine what is going wrong.

ios_webkit_debug_proxy
Listing devices on :9221
Connected :9222 to SIMULATOR (SIMULATOR)

curl localhost:9221/json

[{
   "deviceId": "SIMULATOR",
   "deviceName": "SIMULATOR",
   "url": "localhost:9222"
}]

curl localhost:9222/json

[{
   "devtoolsFrontendUrl": "/devtools/devtools.html?ws=localhost:9222/devtools/page/1",
   "faviconUrl": "",
   "thumbnailUrl": "/thumb/http://localhost:12344/index.html#/",
   "title": "Bienvenido",
   "url": "http://localhost:12344/index.html#/",
   "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/1",
   "appId": "PID:2155"
},{
   "devtoolsFrontendUrl": "/devtools/devtools.html?ws=localhost:9222/devtools/page/2",
   "faviconUrl": "",
   "thumbnailUrl": "/thumb/",
   "title": "",
   "url": "",
   "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/2",
   "appId": "PID:2153"
}]      

Visual code error

Launching for ios (This may take a while)...
Launching app (This may take a while)...
Attaching to ios
Configuring debugging proxy
Unable to find webview

Visual Code launch.json


{
  "name": "Run iOS on simulator",
   "type": "cordova",
   "request": "launch",
   "platform": "ios",
   "target": "emulator",
   "port": 9223,
   "cwd": "${workspaceRoot}"
}

Ports 9222 or 9221 give me an error --> Unable to find iOS target device/simulator. Try specifying a different "port" parameter in launch.json

I also have this problem previously. After I changed the port number. The simulator runs well and the app is launched correctly. But It seems all breakpoints are "Unverified Breakpoints" so that I can't debug my app.

The Visual Code console:

Launching for ios (This may take a while)...
Launching app (This may take a while)...
Attaching to ios
Configuring debugging proxy
Attaching to app.

@imacnu It looks like the app is showing up in the list, but we are not detecting it appropriately. Is your project an ionic project? Have you modified your config.xml to change the start page to point somewhere other than the default index.html?

@guillaumejenkins did some work to make ionic serve work for ionic apps, and that looks like it should be happening in this case.

Hi, no, its a plolyer with cordoba project. I don´t modificate config file ...

@imacnu Your app is being served from a local server, as shown by this line of output: "url": "http://localhost:12344/index.html#/",. That is the reason our extension is not able to find the webview. We only understand these URLs if your app is an Ionic app and you are running a live reload session, but that is not your case based on the Visual Studio Code output you posted.

Default Cordova apps out of the box are not served from a local server when run, so we need to understand why yours is behaving like that. A few questions for you to help us understand:

  1. Do you know anything about a local server running on port 12344 of your Mac? Before running your Cordova app, are you running a separate command to start a local server to serve your app?
  2. If you look in config.xml, do you see <content src="index.html"/> somewhere? If not, what is the value of your <content .../> tag?
  3. How did you create your project initially? Did you create it using the cordova create myProject command?

Its complicated. Is a Polymer Js web app that do deploy on Cordova app, its run at localhost:12344, not is a standar Cordova Project (cordova create ...). Run fine on ios simulator and iPhone, but i want debugger from Vsual Code

I see. That is not a scenario we had imagined when we implemented our debugging experience. As I previously mentioned, we don't currently support attaching to an app that is being served from a server unless it's an Ionic app doing a live reload session (and in that case, the extension is in control of the server, so it allows us to connect properly to the running app).

I will bring this up in my team's next meeting, and come back to you as soon as possible.

Thank you, great support

@imacnu I've just created an experimental branch with support for your scenario. If you are willing to build our extension from sources and install that custom version, I believe it would allow you to debug your app (no guarantee!). Here are the steps:

  1. Clone our repo
  2. Checkout the following branch: git checkout iosAttachToArbitraryUrl
  3. Follow the instructions in the first section (Development setup) of our contributing.md readme to build our extension from sources
  4. Once the extension is built, run npm install -g vsce to install VSCode's extension manager, and then run vsce package at the root of our repo to create a .vsix file (an installer for our extension)
  5. Go to VSCode and uninstall our extension (to avoid conflicts)
  6. Once you have restarted VSCode, drag & drop the .vsix file you created in step 4 to a VSCode window; this should install your custom version of the extension and prompt you for restart
  7. Once you have the custom version installed, add this to your launch.json in your "Run iOS on Simulator": "attachUrlOverride": "http://localhost:12344" (of course, change the localhost:12344 appropriately if you change your PolymerJS server)
  8. If all goes well you should now be able to F5 and debug correctly

It should work for iOS devices as well (add the attachUrlOverride in the appropriate launch configurations), but again, I haven't really tested this, so no guarantee :)

Let me know if you run into any issues while trying to build and install the custom version of the extension. Also, keep in mind that you might want to uninstall this extension and reinstall the official one once you're done, to make sure you get any update we release in the future.

HI, im blocked in fourth step :

screen shot 2016-04-11 at 09 38 38

@imacnu Have you installed gulp globally: "npm install -g gulp"?

@indy7 This issue hasn't been updated in a while; are you still seeing the Unable to find webview error? I also noticed that you mention Ionic 2; we don't currently support debugging in Ionic 2.

@imacnu We haven't heard from you trying to set up the custom build to debug your meteor app; if you are still interested, please create a new issue so that we can track that separately.

@zhouhao27 Are your breakpoints still unverified? Are you in an Ionic 2 project? Based on your other open issue, it looks like you indeed are in an Ionic 2 project and that is the cause for your unverified breakpoints. We will track the Ionic 2 support using your other open issue.

Hey everyone, it seems this issue has become stale, so I'll be closing this. We have a separate issue tracking Ionic 2 debugging not being supported. @indy7, if you are still seeing the "Unable to find webview" error after increasing the attachAttempts and attachDelay properties in your launch.json, please reopen this issue.

Thanks everyone for the feedback!

Still seeing this issue.
In more detail, i am trying to debug an app using 'launch' request which seems to work fine.
The simulator is running an iPhone device by default and i am trying to switch to an ipad, which causes the app to close of course.
So now i am trying the 'attach' request and then i get the error 'unable to find webview'

Thx.

When you try to attach, is your application running in the foreground on the iOS simulator?

If it is, could you please follow the steps in #87 (comment) so we can work out what the issue is.

Hi @MSLaguana ,
My application is not running in the foreground - i assumed the 'attach' request referred to an existing instance of a simulator...and not the existing instance of the app.
I was invoking a simulator manually since i was trying to control the device i am simulating which is now solved by your answer to issue #174.

I hate to open up such an old issue but I'm experiencing the same problem trying to attach to an Ionic 1 app with live reload on the simulator. I can successfully attach when the simulator is not running live reload.

If I try to run ios on simulator from the plugin with livereload: true, the ionic dev server times out even after bumping the timeout to 100000. The app loads but the plugin times out.

If I can get livereload working this plugin will be a huge game changer.

Here's my output from the steps above:

ios_webkit_debug_proxy  
Listing devices on :9221  
Connected :9222 to SIMULATOR (SIMULATOR)  
curl localhost:9222/json
[{
   "devtoolsFrontendUrl": "/devtools/devtools.html?ws=localhost:9222/devtools/page/1",
   "faviconUrl": "",
   "thumbnailUrl": "/thumb/http://192.168.0.20:8101/#/login",
   "title": "Sign-In",
   "url": "http://192.168.0.20:8101/#/login",
   "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/1",
   "appId": "PID:91028"
}]
svekl commented

Hi @markacianfrani, thanks for report, I investigated on you issue and found out that Ionic 1 has slightly different output then extension is waiting for, I created a PR #359 addressing this issue, so, you can expect fix soon.

@svekl thank you so much for looking into this. I updated to 1.3.2 but Im still getting the same issues. When I try to attach to a running simulator running livereload I get unable to find webview.

Here's my config

        {
            "name": "Attach to running iOS on simulator",
            "type": "cordova",
            "request": "attach",
            "attachAttempts": 5,
            "attachDelay": 5000,
            "platform": "ios",
            "target": "emulator",
            "port": 9222,
            "sourceMaps": true,
            "cwd": "${workspaceRoot}"
        },

When I try to just run ios simulator Im getting "The emulate command has been renamed." I thought maybe my global ionic/cordova installs mightve been different versions because I had ionic installed in the project and was also running nvm at one point but I removed it and the only version I have now is 3.19.

It looks like somewhere in the check for the ionic version, its thinking its not v3

@svekl your PR #363 fixes this! thank you!

svekl commented

@markacianfrani Glad to hear! I was also able to reproduce your issue with Run iOS on simulator, fixed it in this PR too. Sorry for not keeping you in touch, we are still testing it because Ionic behaves differently in different combinations.

svekl commented

@markacianfrani Version 1.3.3 is released today, it includes changes from this PR. Thanks again for report!

I know this issue is closed, but I'm seeing similar issue when I use 'Attach to running iOS on device'.
I have not been able to get 'Run iOS on device' working, so instead I tried to run 'ionic cordova run ios --device --livereload' in a console and hoped I would be able to simply attach.

I get this error:
[cordova-tools] Error processing "attach": Error: Unable to find webview at retry (/Users//.vscode/extensions/vsmobile.cordova-tools-1.3.10/out/src/debugger/cordovaDebugAdapter.js:917:19)

versions:
ionic --version: 3.20.0
cordova --version: 8.0.0
npm --version: 5.6.0
node --version: v10.1.0

If I try to run 'Run iOS on device' then I get the following error

Installing app on device
Launching app
Unable to mount developer disk image.

itoys commented

Hi @jkristia
We are using https://github.com/google/ios-webkit-debug-proxy/ under the hood to detect webview's.
Your issue related to this google/ios-webkit-debug-proxy#250
We are looking for all possible way to solve this!

Thanks!

I have the same issues as like you @jkristia on my Ionic 3 project. Have you found the solution? Thanks.