Skip to content

Added PNG export feature for preview screenshots#138

Open
Lishhhh07 wants to merge 1 commit into
Debmallya-03:mainfrom
Lishhhh07:exportfeat
Open

Added PNG export feature for preview screenshots#138
Lishhhh07 wants to merge 1 commit into
Debmallya-03:mainfrom
Lishhhh07:exportfeat

Conversation

@Lishhhh07
Copy link
Copy Markdown
Contributor

Implemented an Export Image feature that allows users to capture and download the current preview as a PNG screenshot directly from the preview section.

Changes Made
Added an Export Image option in the preview header
Implemented screenshot capture for the currently rendered preview/UI component
Enabled automatic download of the captured preview as a .png file

Recording.2026-05-26.172544.mp4

CLOSES #107

Copilot AI review requested due to automatic review settings May 26, 2026 11:57
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 26, 2026

Someone is attempting to deploy a commit to the debmallya-03's projects Team on Vercel.

A member of the Team first needs to authorize it.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 26, 2026

Deploy Preview for webifynet ready!

Name Link
🔨 Latest commit 330c693
🔍 Latest deploy log https://app.netlify.com/projects/webifynet/deploys/6a158a9cdc95c20008c1fea6
😎 Deploy Preview https://deploy-preview-138--webifynet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a “Export Image” capability to capture the Live Preview as a PNG using html2canvas, with a small adjustment to global security headers and inclusion of a few local helper scripts.

Changes:

  • Add html2canvas dependency and implement PNG export from the preview UI.
  • Update next.config.ts headers route matcher to exclude /_next paths.
  • Add three Python scripts intended to patch a local app/page.tsx file.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
package.json Adds html2canvas dependency used for image export.
next.config.ts Adjusts the headers matcher to skip /_next assets.
app/page.tsx Implements exportImage() and adds an “Export Image” button in the preview header.
fix_syntax.py Adds a local one-off script that edits app/page.tsx via absolute path.
fix_syntax2.py Adds a local one-off script that edits app/page.tsx via absolute path and hard-coded line ranges.
fix_syntax3.py Adds a local one-off script that edits app/page.tsx via absolute path and pattern matching.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/page.tsx
@@ -1,4 +1,4 @@
"use client"
"use client"
Comment thread app/page.tsx
Comment on lines +1178 to +1181
const tempIframe = document.createElement("iframe")
tempIframe.style.cssText = `position:fixed;left:-9999px;top:0;width:${width}px;height:${height}px;border:none;`
document.body.appendChild(tempIframe)
tempIframe.srcdoc = combinedHtml
Comment thread app/page.tsx
Comment on lines +1164 to +1165
try {
const { default: html2canvas } = await import("html2canvas")
Comment thread app/page.tsx
Comment on lines +1210 to +1211
document.body.removeChild(tempIframe)
toast.dismiss(loadingToast)
Comment thread app/page.tsx
Comment on lines +1233 to +1239
} catch (err) {
console.error("Export image error:", err)
toast.dismiss(loadingToast)
toast.error("Export failed", {
description: err instanceof Error ? err.message : "Unknown error",
})
}
Comment thread fix_syntax.py
Comment on lines +1 to +50
with open(r'c:\Users\lishi\webify\Webify\app\page.tsx', 'r', encoding='utf-8') as f:
lines = f.readlines()

# Find the problematic area - lines around 1123-1134 (0-indexed: 1122-1133)
# Looking for the pattern: "} catch {}" followed by "} catch {"
i = 0
fixes = 0
while i < len(lines):
# Find " } catch {}" followed by empty line and " } catch {"
stripped = lines[i].rstrip()
if stripped == ' } catch {}' and i + 2 < len(lines):
next_non_empty = i + 1
while next_non_empty < len(lines) and lines[next_non_empty].strip() == '':
next_non_empty += 1
if next_non_empty < len(lines) and '} catch {' in lines[next_non_empty]:
# Found duplicate - remove from i+1 to end of duplicate catch block
# Find the closing } of the duplicate catch
end = next_non_empty + 1
brace_count = 1 if '{' in lines[next_non_empty] and '}' not in lines[next_non_empty].split('{', 1)[1] else 0
if lines[next_non_empty].rstrip().endswith('{'):
# Multi-line catch block
while end < len(lines) and brace_count > 0:
if '{' in lines[end]:
brace_count += lines[end].count('{')
if '}' in lines[end]:
brace_count -= lines[end].count('}')
end += 1
else:
# Single line like "} catch {\n }\n"
end = next_non_empty + 1
while end < len(lines) and lines[end].strip() != '':
if lines[end].strip() == '}':
end += 1
break
end += 1

print(f"Removing duplicate catch at lines {i+2}-{end} (1-indexed)")
print(f" Content: {''.join(lines[i+1:end])}")
# Remove the blank line(s) and duplicate catch block
del lines[i+1:end]
fixes += 1
continue
i += 1

if fixes > 0:
with open(r'c:\Users\lishi\webify\Webify\app\page.tsx', 'w', encoding='utf-8') as f:
f.writelines(lines)
print(f'\nFixed {fixes} duplicate catch blocks')
else:
print('No fixes needed')
Comment thread fix_syntax2.py
Comment on lines +1 to +24
with open(r'c:\Users\lishi\webify\Webify\app\page.tsx', 'r', encoding='utf-8') as f:
lines = f.readlines()

# Remove lines 1123-1125 (0-indexed: 1122-1124) - the duplicate "} catch { }"
# And lines 1132-1135 (0-indexed: 1131-1134) - the duplicate "} catch { // corrupted... }"

# Work backwards to avoid index shifting
# Second duplicate: lines 1133-1135 (1-indexed), 0-indexed 1132-1134
del lines[1132:1135]

# First duplicate: lines 1123-1125 (1-indexed), 0-indexed 1122-1124
del lines[1122:1125]

with open(r'c:\Users\lishi\webify\Webify\app\page.tsx', 'w', encoding='utf-8') as f:
f.writelines(lines)

print('Fixed')

# Verify
with open(r'c:\Users\lishi\webify\Webify\app\page.tsx', 'r', encoding='utf-8') as f:
lines = f.readlines()
print('Lines 1115-1135:')
for i in range(1114, 1135):
print(f'{i+1}: {lines[i]}', end='')
Comment thread fix_syntax2.py
Comment on lines +1 to +24
with open(r'c:\Users\lishi\webify\Webify\app\page.tsx', 'r', encoding='utf-8') as f:
lines = f.readlines()

# Remove lines 1123-1125 (0-indexed: 1122-1124) - the duplicate "} catch { }"
# And lines 1132-1135 (0-indexed: 1131-1134) - the duplicate "} catch { // corrupted... }"

# Work backwards to avoid index shifting
# Second duplicate: lines 1133-1135 (1-indexed), 0-indexed 1132-1134
del lines[1132:1135]

# First duplicate: lines 1123-1125 (1-indexed), 0-indexed 1122-1124
del lines[1122:1125]

with open(r'c:\Users\lishi\webify\Webify\app\page.tsx', 'w', encoding='utf-8') as f:
f.writelines(lines)

print('Fixed')

# Verify
with open(r'c:\Users\lishi\webify\Webify\app\page.tsx', 'r', encoding='utf-8') as f:
lines = f.readlines()
print('Lines 1115-1135:')
for i in range(1114, 1135):
print(f'{i+1}: {lines[i]}', end='')
Comment thread fix_syntax3.py
@@ -0,0 +1,36 @@
with open(r'c:\Users\lishi\webify\Webify\app\page.tsx', 'r', encoding='utf-8') as f:
Comment thread fix_syntax3.py
Comment on lines +1 to +36
with open(r'c:\Users\lishi\webify\Webify\app\page.tsx', 'r', encoding='utf-8') as f:
lines = f.readlines()

# Find ALL remaining "} catch {" duplicates that follow a "} catch {}"
to_delete = []
i = 0
while i < len(lines):
if lines[i].strip() == '} catch {}':
# Check if next non-empty line starts another catch
j = i + 1
while j < len(lines) and lines[j].strip() == '':
j += 1
if j < len(lines) and lines[j].strip().startswith('} catch {'):
# Find end of this duplicate catch block
end = j + 1
if lines[j].strip() == '} catch {':
# Multi-line - find closing }
while end < len(lines):
if lines[end].strip() == '}':
end += 1
break
end += 1
# Mark lines i+1 to end for deletion (keep the first } catch {})
for k in range(i+1, end):
to_delete.append(k)
print(f"Found duplicate catch at lines {i+2}-{end} (1-indexed)")
i += 1

# Delete in reverse order
for idx in sorted(to_delete, reverse=True):
del lines[idx]

with open(r'c:\Users\lishi\webify\Webify\app\page.tsx', 'w', encoding='utf-8') as f:
f.writelines(lines)

print(f"Deleted {len(to_delete)} lines")
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.

[feature]:Add PNG export option for preview screenshots

2 participants