8ad8242c41
- 원인: 설명란 이미지 "선택"은 편집기 표시라 기본 Ctrl+C 로는 아무것도 복사되지 않았고, 브라우저 "이미지 복사"는 <img src=첨부 주소> HTML 을 같이 넣어 로그인 없는 프로그램(카카오톡·한글 등)엔 빈칸 - copyImageToClipboard: 캔버스로 PNG 변환 → navigator.clipboard.write(ClipboardItem, Promise) - 설명란 고른 이미지 Ctrl+C(한글 입력 상태 e.code), 글자를 골라 둔 상태면 기본 복사 그대로 - 이미지 보기 창: 아래 막대 [복사] 버튼 + Ctrl+C, 위쪽 알림 - tests/js/image_copy.browser.test.js (Edge 로 9항목 통과), project.js 버전 20261015a, 도움말·문서 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
127 lines
7.4 KiB
JavaScript
127 lines
7.4 KiB
JavaScript
// 실제 브라우저 — 설명란 이미지 복사(2026-10-15). 클립보드에 PNG 그림만(첨부 주소 HTML 없이) 들어가는지:
|
||
// ① 설명란 이미지를 눌러 고른 뒤 Ctrl+C ② 더블클릭 이미지 보기 창의 [복사] 버튼 ③ 그 창에서 Ctrl+C.
|
||
// 원본이 JPEG 여도 PNG 로 바뀌고 크기는 원본 그대로인지도 본다. 서버는 가짜(이 파일의 http 서버), 화면은 실제 템플릿 렌더 결과.
|
||
// python tests/js/render_project.py
|
||
// NODE_PATH=<playwright 경로> PJ_TEST_BROWSER=<Chrome/Edge 경로> node tests/js/image_copy.browser.test.js
|
||
const assert = require("node:assert/strict");
|
||
const fs = require("node:fs"), path = require("node:path"), http = require("node:http");
|
||
let chromium;
|
||
try { ({ chromium } = require("playwright")); } catch (_) { ({ chromium } = require("playwright-core")); }
|
||
const ROOT = path.resolve(__dirname, "../.."), OUT = path.join(__dirname, ".out"), STATIC = path.join(ROOT, "app/static");
|
||
const IMG = path.join(STATIC, "dbx/inline.jpg"); // JPEG 777×832 — PNG 로 바뀌어야 한다
|
||
|
||
const server = http.createServer(async (req, res) => {
|
||
const url = new URL(req.url, "http://localhost");
|
||
const json = (code, body) => { res.statusCode = code; res.setHeader("Content-Type", "application/json"); res.end(JSON.stringify(body)); };
|
||
if (url.pathname === "/project/p/1") { res.setHeader("Content-Type", "text/html; charset=utf-8"); res.end(fs.readFileSync(path.join(OUT, "project_render.html"))); return; }
|
||
if (url.pathname === "/project/api/attachments/7/inline") { res.setHeader("Content-Type", "image/jpeg"); res.end(fs.readFileSync(IMG)); return; }
|
||
if (url.pathname.startsWith("/project/api/")) {
|
||
const task = /^\/project\/api\/tasks\/(\d+)$/.exec(url.pathname);
|
||
if (task && req.method === "GET") {
|
||
return json(200, { task: { id: +task[1], title: "이미지 작업", project_id: 1, stage_id: 11, priority: "normal", assignee_email: "",
|
||
description: '<p>글자</p><p><img src="/project/api/attachments/7/inline" alt="외벽" width="300"></p>',
|
||
subtasks: [], links: [], followers: [], access: "full", completed_at: null } });
|
||
}
|
||
if (url.pathname.endsWith("/comments")) return json(200, { comments: [], events: [], features: {} });
|
||
if (url.pathname.endsWith("/attachments")) return json(200, { attachments: [] });
|
||
if (url.pathname.endsWith("/members")) return json(200, { members: [{ user_email: "me@test.local" }] });
|
||
if (url.pathname.endsWith("/live-version")) return json(200, { ts: "v1" });
|
||
if (url.pathname.endsWith("/alerts")) return json(200, { me: "me@test.local", latest_id: 0, alerts: [] });
|
||
return json(200, {});
|
||
}
|
||
if (url.pathname.startsWith("/static/")) {
|
||
const file = path.join(STATIC, decodeURIComponent(url.pathname.slice("/static/".length)));
|
||
if (file.startsWith(STATIC) && fs.existsSync(file)) {
|
||
res.setHeader("Content-Type", file.endsWith(".js") ? "text/javascript" : file.endsWith(".css") ? "text/css" : "application/octet-stream");
|
||
res.end(fs.readFileSync(file)); return;
|
||
}
|
||
}
|
||
res.statusCode = 404; res.end("");
|
||
});
|
||
|
||
// 클립보드 내용 — 형식 목록과 PNG 크기(그림으로 다시 읽어 본다)
|
||
async function readClipboard(page) {
|
||
return page.evaluate(async () => {
|
||
const items = await navigator.clipboard.read();
|
||
const types = items.flatMap(i => i.types);
|
||
let w = 0, h = 0;
|
||
if (types.includes("image/png")) {
|
||
const bmp = await createImageBitmap(await items[0].getType("image/png"));
|
||
w = bmp.width; h = bmp.height;
|
||
}
|
||
return { types, w, h };
|
||
});
|
||
}
|
||
// 복사는 비동기(PNG 변환) — 클립보드에 그림이 들어올 때까지 기다린다(최대 5초)
|
||
async function waitClipPng(page) {
|
||
for (let i = 0; i < 50; i++) {
|
||
if ((await readClipboard(page)).types.includes("image/png")) return;
|
||
await page.waitForTimeout(100);
|
||
}
|
||
}
|
||
async function clearClipboard(page) {
|
||
await page.evaluate(() => navigator.clipboard.writeText("비움"));
|
||
}
|
||
|
||
(async function () {
|
||
await new Promise(r => server.listen(0, "127.0.0.1", r));
|
||
const base = "http://127.0.0.1:" + server.address().port;
|
||
const browser = await chromium.launch(process.env.PJ_TEST_BROWSER ? { executablePath: process.env.PJ_TEST_BROWSER } : {});
|
||
const context = await browser.newContext({ viewport: { width: 1600, height: 1000 } });
|
||
await context.grantPermissions(["clipboard-read", "clipboard-write"], { origin: base });
|
||
const page = await context.newPage();
|
||
const errors = [];
|
||
page.on("pageerror", e => errors.push(String(e)));
|
||
const ok = (name, cond, extra) => { assert.ok(cond, name + (extra === undefined ? "" : " → " + JSON.stringify(extra))); console.log("PASS " + name); };
|
||
try {
|
||
await page.goto(base + "/project/p/1?task=1");
|
||
await page.waitForFunction(() => { const i = document.querySelector("#pj-t-desc img"); return i && i.complete && i.naturalWidth > 0; });
|
||
const img = page.locator("#pj-t-desc img");
|
||
|
||
// ① 설명란: 이미지 고르기 → Ctrl+C
|
||
await clearClipboard(page);
|
||
await img.click();
|
||
ok("이미지를 누르면 고른 표시", await img.evaluate(n => n.classList.contains("pj-img-selected")));
|
||
await page.keyboard.press("Control+c");
|
||
await waitClipPng(page);
|
||
let clip = await readClipboard(page);
|
||
ok("설명란 Ctrl+C = PNG 그림만(첨부 주소 HTML 없음)", clip.types.length === 1 && clip.types[0] === "image/png", clip);
|
||
ok("원본 크기 그대로(화면 표시 폭 300 이 아니라 777×832)", clip.w === 777 && clip.h === 832, clip);
|
||
ok("복사 알림", /이미지를 복사했습니다/.test(await page.locator(".erp-toast").textContent()));
|
||
|
||
// 글자를 드래그해 둔 상태면 글자 복사 그대로(이미지로 가로채지 않음)
|
||
await clearClipboard(page);
|
||
await page.evaluate(() => {
|
||
const p = document.querySelector("#pj-t-desc p"), r = document.createRange();
|
||
r.selectNodeContents(p); const s = getSelection(); s.removeAllRanges(); s.addRange(r);
|
||
});
|
||
await page.keyboard.press("Control+c");
|
||
await page.waitForTimeout(300);
|
||
clip = await readClipboard(page);
|
||
ok("글자를 골라 둔 Ctrl+C 는 브라우저 기본 복사(이미지 아님)", !clip.types.includes("image/png"), clip);
|
||
|
||
// ② 이미지 보기 창 [복사] ③ 그 창 Ctrl+C
|
||
await page.evaluate(() => getSelection().removeAllRanges());
|
||
const [popup] = await Promise.all([page.waitForEvent("popup"), img.dblclick()]);
|
||
await popup.waitForFunction(() => { const i = document.getElementById("img"); return i && i.naturalWidth > 0; });
|
||
await clearClipboard(page);
|
||
await popup.click("#copy");
|
||
await popup.waitForFunction(() => document.getElementById("msg").classList.contains("show"));
|
||
clip = await readClipboard(page);
|
||
ok("보기 창 [복사] = PNG 그림만, 원본 크기", clip.types.join() === "image/png" && clip.w === 777 && clip.h === 832, clip);
|
||
ok("보기 창 복사 알림", /이미지를 복사했습니다/.test(await popup.locator("#msg").textContent()));
|
||
|
||
await clearClipboard(page);
|
||
await popup.keyboard.press("Control+c");
|
||
await waitClipPng(page);
|
||
clip = await readClipboard(page);
|
||
ok("보기 창 Ctrl+C = PNG 그림만", clip.types.join() === "image/png", clip);
|
||
|
||
ok("페이지 스크립트 오류 없음", errors.length === 0, errors);
|
||
console.log("ALL PASS");
|
||
} finally {
|
||
await browser.close();
|
||
server.close();
|
||
}
|
||
})().catch(e => { console.error("FAIL " + e.message); process.exit(1); });
|