# HTTP 웹사이트용 Chrome 및 Firefox 웹 푸시

<Aside type="caution" title="주의">
다음 지침은 각 플랫폼에 고유한 첫 번째 문서를 **제외하고** Chrome 및 Firefox 구성에 대해 **통합**되어 있습니다.
</Aside>

## 구성

1. 프로젝트를 생성하는 동안 웹 푸시 옵션을 선택합니다.

<img src="/web-push-notifications-chrome-firefox-web-push-for-http-websites-1.webp" alt=""/>

2. http를 선택하고 사이트 URL과 프로젝트 이름을 입력합니다.

<img src="/web-push-notifications-chrome-firefox-web-push-for-http-websites-2.webp" alt=""/>

3. FCM 프로젝트 자격 증명으로 Chrome과 Firefox를 모두 구성합니다.

<Aside type="note">
[Chrome 및 Firefox 구성 가이드](/ko/developer/first-steps/connect-messaging-services/chrome-configuration/)에서 FCM 자격 증명을 얻는 방법을 알아보세요.
</Aside>

<img src="/web-push-notifications-chrome-firefox-web-push-for-http-websites-3.webp" alt=""/>

## 통합

**1.** 웹사이트의 루트 디렉터리에 다음 내용으로 **pushwoosh-web-pushes-http-sdk.js** 파일을 생성합니다:

```javascript
var pushwoosh = {
	PUSHWOOSH_APPLICATION_CODE: 'XXXX-XXXX',
	PUSHWOOSH_APPLICATION_CODE_GET_PARAMETER: 'pw_application_code',
	init: function (applicationCode) {
		this.PUSHWOOSH_APPLICATION_CODE = applicationCode;
		window.addEventListener('message', this.pwReceiveMessage, false);
	},
	tryInitUsingGetParameter: function () {
		var applicationCode = this.getQueryVariable(this.PUSHWOOSH_APPLICATION_CODE_GET_PARAMETER);
		console.log(applicationCode);
		if (applicationCode) {
			this.init(applicationCode);
		}
	},
	pwReceiveMessage: function (event) {
		if (event.data == 'allowPushNotifications') {
			localStorage.setItem('pwAllowPushNotifications', true);
		}
	},
	isBrowserChrome: function () {
		return navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
	},
	isBrowserFirefox: function () {
		return navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
	},
	isBrowserSafari: function () {
		return navigator.userAgent.toLowerCase().indexOf('safari') > -1 && !this.isBrowserChrome();
	},
	isBrowserSupported: function () {
		return this.isBrowserChrome() || this.isBrowserFirefox();
	},
	subscribeAtStart: function () {
		if (this.isBrowserSupported()) {
			if (null === localStorage.getItem('pwAllowPushNotifications')) {
				this.showSubscriptionWindow();
			}
		}
	},
	isSubscribedForPushNotifications: function () {
		return true == localStorage.getItem('pwAllowPushNotifications');
	},
	showSubscriptionWindow: function () {
		if (this.isBrowserSupported()) {
			var windowWidth = screen.width / 2;
			var windowHeight = screen.height / 2;

			var windowLeft = screen.width / 2 - windowWidth / 2;
			var windowRight = screen.height / 2 - windowHeight / 2;

			var URL = 'https://' + this.PUSHWOOSH_APPLICATION_CODE + '.chrome.pushwoosh.com/';
			var pwSubscribeWindow = window.open(URL, '_blank', 'width=' + windowWidth + ',height=' + windowHeight + ',resizable=yes,scrollbars=yes,status=yes,left=' + windowLeft + ',top=' + windowRight);
		}
	},
	getQueryVariable: function (variable) {
		// document.currentScript won't work if this code is called from function in event lister
		if (document.currentScript) {
			var urlParts = document.currentScript.src.split('?');
			if (typeof urlParts[1] !== 'undefined') {
				var vars = urlParts[1].split('&');
				for (var i = 0; i < vars.length; i++) {
					var pair = vars[i].split('=');
					if (pair[0] == variable) {
						return pair[1];
					}
				}
			}
		}
		else {
			console.error('Cannot get current script address');
		}
		return null;
	}
};
pushwoosh.tryInitUsingGetParameter();
```

**2.** 이전 파일을 웹사이트에 포함하고 XXXXX-XXXXX 대신 **애플리케이션 코드**를 사용하여 초기화합니다.

```javascript
<!--[if !IE]><!-->
    <script src="/pushwoosh-web-pushes-http-sdk.js?pw_application_code=XXXXX-XXXXX"></script>
<!--<![endif]-->
```

**3.** 푸시 구독 버튼을 생성하려면 다음을 사용합니다:

```txt
<button onclick="pushwoosh.showSubscriptionWindow()">Subscribe to push notifications</button>
```

**4.** 또는, (위의 3번과 반대로) 알림 구독이 자동으로 팝업되도록 하려면 다음을 사용합니다:

```javascript
<script>pushwoosh.subscribeAtStart();</script>
```

<Aside type="note">
#### 중요

브라우저의 보안 정책으로 인해 팝업 창은 사용자의 허가가 있어야만 허용됩니다. 팝업 차단기는 사용자의 직접적인 조치 없이 자동으로 작동합니다. \
브라우저는 버튼 클릭으로 명시적으로 허용할 때까지 팝업을 자동으로 차단합니다.\
위에서 언급한 푸시 구독 버튼은 추가적인 사용자 권한 없이 완벽하게 작동합니다.
</Aside>

<img src="/web-push-notifications-chrome-firefox-web-push-for-http-websites-4.webp" alt=""/>

<img src="/web-push-notifications-chrome-firefox-web-push-for-http-websites-5.webp" alt=""/>

결과적으로, 사용자는 웹사이트에서 푸시 알림을 구독하라는 메시지를 받게 됩니다:

<img src="/web-push-notifications-chrome-firefox-web-push-for-http-websites-6.webp" alt=""/>