Skip to content

feat: Add native screenshot capture for webview content#446

Draft
Copilot wants to merge 7 commits intomainfrom
copilot/add-screenshot-functionality
Draft

feat: Add native screenshot capture for webview content#446
Copilot wants to merge 7 commits intomainfrom
copilot/add-screenshot-functionality

Conversation

Copy link
Contributor

Copilot AI commented Feb 16, 2026

Screenshot Feature Implementation Plan

Phase 1: API Design & TypeScript

  • Add captureScreenshot method to TypeScript definitions
  • Add screenshot event listener types
  • Add screenshot options (removed quality parameter as PNG is lossless)

Phase 2: Android Implementation

  • Implement captureScreenshot method in WebViewDialog
  • Add toolbar button for screenshot capture
  • Capture WebView bitmap and convert to base64 PNG
  • Return screenshot data to plugin
  • Add screenshot button to toolbar layout
  • Add screenshot button string resources
  • Create camera icon drawable
  • Fix targetId checks to only include when explicitly provided
  • Set PNG quality to 0 (ignored) to clarify it's not applicable
  • Remove hardcoded background from screenshot button
  • Fix formatting (lint)

Phase 3: iOS Implementation

  • Implement captureScreenshot method in WKWebViewController
  • Add toolbar button for screenshot capture using camera symbol
  • Capture WKWebView snapshot and convert to base64 PNG
  • Return screenshot data to plugin
  • Add screenshot to BarButtonItemType enum
  • Configure screenshot button in toolbar
  • Fix targetId checks to only include when explicitly provided
  • Remove unused quality parameter
  • Fix Swift compilation errors

Phase 4: Plugin Integration

  • Add captureScreenshot method to InAppBrowserPlugin (Android)
  • Add captureScreenshot method to InAppBrowserPlugin (iOS)
  • Add web implementation (fallback error)
  • Add screenshot button callback to WebViewCallbacks
  • Implement screenshotCaptured callback in plugin

Phase 5: Testing & Documentation

  • Address all code review feedback
  • Build TypeScript successfully
  • Update README with auto-generated API documentation
  • Remove quality parameter (PNG is lossless)
  • Add screenshot to toolbar when showScreenshotButton is true
  • Style screenshot button consistently with other buttons
  • Run fmt command and fix formatting issues
  • Fix Swift warnings and errors
  • Implementation complete and ready for testing
Original prompt

This section details on the original issue you should resolve

<issue_title>feat: Take Screenshot</issue_title>
<issue_description>### Current problem

Currently to take a screenshot of a web page I am injecting a script that contains html2canvas, posting that to my own server and then using a deeplink to open the upload image in my app. This mostly works fine (apart from where html2canvas sometimes fails.

Preferred solution

It would be great if there was an ability to take a screenshot from within the webview. Ideally there would be a button for this as well so that while browsing a page we could take a screenshot of it and feed this back to the source app somehow. I'm not sure if this is possible or not - though the whering app seems to do this:

Image

Alternative options

I can't think of any. However, if it's possible to expose a screenshot of the app to the webview itself even this would replace the requirement for html2canvas and would create more consistent screenshots. The process would likely be faster too.

Additional context

The full flow from the whering app:

Image

Image

Image

Before submitting

Fastest way to get this feature added

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits February 16, 2026 15:48
…id implementation

Co-authored-by: riderx <4084527+riderx@users.noreply.github.com>
Co-authored-by: riderx <4084527+riderx@users.noreply.github.com>
…etId checks

Co-authored-by: riderx <4084527+riderx@users.noreply.github.com>
…ckground

Co-authored-by: riderx <4084527+riderx@users.noreply.github.com>
Copilot AI changed the title [WIP] Add screenshot functionality within webview feat: Add native screenshot capture for webview content Feb 16, 2026
Copilot AI requested a review from riderx February 16, 2026 16:06
@riderx
Copy link
Member

riderx commented Feb 16, 2026

@copilot build this filing because of lint. Ensure you run the fmt command and commit the change of the file, or fix the lint if fmt changes nothing.

Co-authored-by: riderx <4084527+riderx@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 16, 2026

@copilot build this filing because of lint. Ensure you run the fmt command and commit the change of the file, or fix the lint if fmt changes nothing.

Fixed in commit 8bfd732. The formatter changed the Bitmap.createBitmap() call to a single line per Java formatting standards.

@riderx
Copy link
Member

riderx commented Feb 16, 2026

@copilot ^
/Users/runner/work/capacitor-inappbrowser/capacitor-inappbrowser/ios/Sources/InAppBrowserPlugin/WKWebViewController.swift:860:16: warning: value 'tintColor' was defined but never used; consider replacing with boolean test
if let tintColor = self.tintColor {
~~~~^~~~~~~~~~~~
!= nil
/Users/runner/work/capacitor-inappbrowser/capacitor-inappbrowser/ios/Sources/InAppBrowserPlugin/WKWebViewController.swift:1514:27: error: missing argument label 'data:' in call
self?.emit("screenshotCapture", ["base64": base64])
^
data:
/Users/runner/work/capacitor-inappbrowser/capacitor-inappbrowser/ios/Sources/InAppBrowserPlugin/WKWebViewController.swift:1695:15: warning: 'catch' block is unreachable because no errors are thrown in 'do' block
} catch {
^

… catch

Co-authored-by: riderx <4084527+riderx@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 16, 2026

@copilot ^
/Users/runner/work/capacitor-inappbrowser/capacitor-inappbrowser/ios/Sources/InAppBrowserPlugin/WKWebViewController.swift:860:16: warning: value '...

Fixed in commit efa234d. Changes made:

  1. Line 860: Changed if let tintColor = self.tintColor to if self.tintColor != nil to fix unused variable warning
  2. Line 1514: Added missing data: argument label in emit call: emit("screenshotCapture", data: ["base64": base64])
  3. Line 1695: Removed unreachable catch block from present() call which doesn't throw errors

@sonarqubecloud
Copy link

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Take Screenshot

2 participants