카카오 인앱 브라우저에서는 navigator.clipboard.writeText
사용이 불가하다.
executeCommand를 사용하자
function checkIsInAppBrowser (): boolean {
return Boolean(
navigator.userAgent.match(
/inapp|NAVER|KAKAOTALK|Snapchat|Line|WirtschaftsWoche|Thunderbird|Instagram|everytimeApp|WhatsApp|Electron|wadiz|AliApp|zumapp|iPhone(.*)Whale|Android(.*)Whale|kakaostory|band|twitter|DaumApps|DaumDevice\/mobile|FB_IAB|FB4A|FBAN|FBIOS|FBSS|SamsungBrowser\/[^1]/i,
),
);
};
function copy (text) {
if (window.navigator?.clipboard && !checkIsInAppBrowser()) {
navigator.clipboard.writeText(text);
} else {
const tempEl = document.createElement('textarea');
tempEl.value = text;
document.body.appendChild(tempEl);
tempEl.select();
document.execCommand('copy');
document.body.removeChild(tempEl);
}
}