Qhov yuav tsum ua tiav: tom qab kuaj xyuas tas, lub website tsuas thov notification permission tom qab tus neeg siv tau ua ib qho kev txiav txim uas nws txhob txwm xaiv, tsis yuam kom nias Allow, tsis xa cov ntsiab lus cuav lossis tsis cuam tshuam, thiab yuav tsum muaj peev xwm lov tes taw FCM registration thaum tus neeg siv xaiv tsis txais xov ntxiv.
Kom txo cov web notification tsis tsim nyog, tsis txhob pib los ntawm kev hloov Firebase project lossis tsim VAPID key tshiab. Kuaj raws li nqe lus no: txoj kev thov permission → permission status hauv Chrome → FCM registration → cov ntsiab lus thiab qhov nquag xa → abusive notifications report. FCM muab txoj kev xa xov rau web, tab sis tsis hloov lub luag haujlwm ntawm lub website hauv kev thov permission thiab xaiv cov ntsiab lus kom tsim nyog (raws li firebase.google.com).
Cais plaub txheej uas ua rau muaj web notification tsis tsim nyog
| Txheej yuav tsum kuaj | Teeb meem uas nquag tshwm | Yam qhia tias tau txheeb xyuas |
|---|---|---|
| Permission prompt interface | Qhia ib lub dialog cuav uas zoo li khawm system, lossis yuam kom tus neeg siv tso cai thiaj pom tau cov ntsiab lus. | Tus neeg siv tseem tsis tau thov, tiam sis twb pom lus caw kom qhib notification lawm. |
| Browser permission | Lub domain tseem tau tso cai xa notification txawm tus neeg siv tsis xav txais ntxiv lawm. | Chrome qhia lub domain hauv daim ntawv teev cov website uas tau tso cai xa notification. |
| FCM registration | Token qub lossis Firebase Installation ID qub tseem raug khaws cia thiab tseem txais xov ntxiv. | Tus account lossis browser twb xaiv tsis txais xov lawm, tiam sis cov ntaub ntawv registration tseem ua haujlwm. |
| Cov ntsiab lus xa | Title cuav uas ua txuj ceeb toom system, xov zoo li chat notification, link txawv txawv lossis xa ntau dhau. | Payload tsis piav meej tias vim li cas thiaj xa thiab yuav coj mus rau qhov twg. |
Chrome thiab Google Web Tools suav tias cov permission request uas ua rau nkag siab yuam kev, cov notification cuav, cov notification dag ntxias lossis kev tshaj tawm software phem yog hom abusive notifications. Yog li, “muaj neeg nias Allow lawm” tsis txhais tias “qhov registration ntawd raug cai” (raws li support.google.com).
Kuaj txoj kev thov permission ua ntej kuaj FCM
Tshem qhov kev thov permission thaum nplooj ntawv nyuam qhuav qhib
Tsis txhob hu Notification.requestPermission() hauv code uas khiav tam sim nplooj ntawv qhib, hauv DOMContentLoaded, hauv automatic timer lossis tom qab redirect uas tus neeg siv tsis tau thov txhob txwm.
Chrome Lighthouse suav tias kev thov notification permission thaum nplooj ntawv tab tom load yog ib qho kev coj tsis zoo. Txoj kev nyab xeeb dua yog piav ua ntej tias tus neeg siv yuav txais xov zoo li cas, ces tsuas qhib permission dialog thaum nws nias ib lub pob sau npe uas qhia meej xwb (raws li developer.chrome.com).
Cov code hauv qab no khiav hauv JavaScript ntawm browser. Lub pob #enable-notifications yuav tsum twb muaj nyob hauv HTML ntawm lub website. Function registerFcmSubscription() yog koj qhov chaw txuas rau Firebase; hloov nws rau qhov function tiag ntawm koj qhov project. Tsis txhob theej lub npe function no yog tias koj qhov project tsis muaj function ntawd.
const enableButton = document.querySelector('#enable-notifications');
if (!enableButton) {
throw new Error('Không tìm thấy nút #enable-notifications');
}
enableButton.addEventListener('click', async () => {
if (!('Notification' in window)) {
showMessage('Trình duyệt này không hỗ trợ thông báo web.');
return;
}
try {
const permission = await Notification.requestPermission();
if (permission === 'granted') {
// Thay bằng hàm đăng ký FCM thật của ứng dụng.
await registerFcmSubscription();
showMessage('Đã bật thông báo. Bạn có thể tắt bất cứ lúc nào.');
} else {
showMessage('Bạn chưa bật thông báo; website vẫn hoạt động bình thường.');
}
} catch (error) {
console.error('Không thể xin quyền thông báo:', error);
showMessage('Không thể bật thông báo lúc này.');
}
});
Tom qab hloov qhov function txuas tas, qhib lub website hauv Chrome profile sim, nias lub pob thiab kuaj kom pom tias permission dialog tsuas tshwm tom qab nias xwb. Yog tus neeg siv tsis kam, tsis txhob tsim FCM registration record.
Tsim lus caw kom tus neeg siv tsis txhob nias yuam kev
- Qhia meej tias tus neeg siv yuav txais dab tsi, xws li “ceeb toom tias koj daim order tau xa tuaj lawm” lossis “muaj message tshiab”, tsis yog sau tias “Nias Allow kom txuas ntxiv” xwb.
- Tsis txhob xauv cov ntsiab lus, video, search results lossis lub pob kaw uas nyob tom qab qhov kev thov tso cai notification.
- Tsis txhob siv duab lossis lus hais uas xyaum lub qhov rais ceeb toom ntawm system, ceeb toom kab mob vais lav, lus ntiag tug, lossis lus thov kom hloov kho browser.
- Muab kev xaiv “Ua dua mam ua” thiab cia tus neeg siv tseem siv tau lub website li qub.
- Muab khawm tua lossis tswj cov ntawv ceeb toom hauv tus account, tsis txhob yuam tus neeg siv mus nrhiav hauv browser cov kev teeb tsa.
Yog website siv ib txheej interface nruab nrab ua ntej lub qhov rais Chrome, txheej ntawd yuav tsum piav qhia kom ncaj ncees thiab tsis tsim kev nyuaj siab. Kev caw cuav yuav ua rau tus neeg siv sau npe yam tsis tau npaj siab thiab yog ib qho cim uas pom ntau hauv kev tsim txom web notification.
Tshawb xyuas kev tso cai rau cov ntawv ceeb toom hauv Chrome
Hauv computer, qhib Chrome ces mus rau Settings → Privacy and security → Site settings → Notifications. Tshawb xyuas lub domain ntawm website hauv cov npe uas tso cai, thaiv, lossis cov npe uas Chrome tab tom ceeb toom kom tus neeg siv rov tshuaj xyuas.
Chrome yuav tshem tau nws tus kheej cov kev tso cai rau cov ntawv ceeb toom ntawm cov website uas Safe Browsing txheeb pom tias tab tom ntxias cov neeg siv kom muab kev tso cai. Chrome kuj yuav txo cov lus thov lossis kom website thov kev tso cai dua. Yog li, kev tso cai raug hloov tsis tas txhais tias FCM puas lawm; xub tshuaj xyuas qhov kev thov kev tso cai thiab lub domain qhov xwm txheej txog kev nyab xeeb (raws li support.google.com).
Txhawm rau kuaj hauv qhov xwm txheej tiag, siv ib qho Chrome profile huv lossis tshem lub domain qhov kev tso cai hauv cov kev teeb tsa, ces ua cov xwm txheej hauv qab no:
- Qhib thawj zaug: yuav tsum tsis txhob cia li qhib lub qhov rais thov kev tso cai.
- Nyeem lo lus piav qhia thiab tsis nias khawm sau npe: yuav tsum tsis txhob tshwm lub browser qhov rais thov kev tso cai.
- Nias khawm sau npe: thaum ntawd Chrome mam tso tawm qhov kev thov kev tso cai.
- Xaiv “Tsis pub”: tseem yuav tsum siv tau cov ntsiab lus tseem ceeb ntawm website.
- Xaiv “Pub”: tsuas tau txais hom ntawv ceeb toom uas tau piav qhia lawm xwb.
- Thim kev tso cai hauv Chrome: system yuav tsum tsis txhob tseem suav tias browser yog ib qho kev sau npe uas tab tom ua haujlwm.
Chrome muaj qhov kev xaiv “Use quieter messaging” los txo cov lus ceeb toom uas cuam tshuam. Qhov no yog browser lub tshuab, tsis yog txoj kev kho lub hauv paus rau website uas thov kev tso cai tas li lossis xa cov ntsiab lus uas tsis cuam tshuam txaus.
Rov tshuaj xyuas Firebase Cloud Messaging thiab kev sau npe txais ntawv ceeb toom
FCM hauv web xav tau kev tso cai rau cov ntawv ceeb toom, service worker thiab HTTPS configuration. Tom qab tau txais kev tso cai lawm, app mam tsim kev sau npe rau browser, khaws cov cim qhia uas tsim nyog rau ntawm server thiab siv nws xa cov ntawv ceeb toom rau tus neeg raug. Hauv koj lub system, tsim ib daim qauv sib piv uas tsawg kawg muaj:
| Nqe lus | Hom phiaj | Tej xwm txheej uas yuav tsum ua |
|---|---|---|
| User lossis account ID | Paub tias qhov kev sau npe yog tus neeg siv twg li. | Rho tawm lossis lov tes taw thaum tus account tawm, tshem kev sau npe, lossis raug rho tawm. |
| Origin lossis domain | Zam kev siv yuam kev qhov kev sau npe los ntawm lwm lub website. | Tsis lees txais cov ntaub ntawv uas tsis phim lub domain uas tau teev tseg. |
| FCM token lossis Firebase Installation ID | Xa cov ntawv ceeb toom mus rau qhov browser version uas raug. | Hloov kho thaum tus nqi hloov; tshem tawm thaum FCM xa qhov yuam kev tias token tsis siv tau. |
| Consent state | Sau tseg tias tus neeg siv tau qhib, tua, lossis tseem tsis tau txiav txim siab. | Tsis txhob kwv yees tias “tau sau npe lawm” tsuas yog vim yav dhau los muaj token. |
| Topic lossis pawg txais ntawv ceeb toom | Txwv hom ntsiab lus uas yuav xa tau. | Tshem kev sau npe ntawm pawg thaum tus neeg siv tshem qhov kev xaiv ntawd. |
Tsis txhob xa ib daim ntawv ceeb toom tshaj tawm mus rau tag nrho cov token tsuas yog vim lawv tseem nyob hauv database. Txhua lub phiaj xwm yuav tsum muaj cov cai xaiv cov neeg txais, lub hom phiaj, lub sijhawm siv tau thiab ib txoj kev tshem tawm cov neeg uas twb tua kev txais ntawv ceeb toom lawm. Firebase kuj qhia kom tswj cov cim qhia ntawm installation thiab tsis txhob muab cov txheej txheem tswj kev sau npe qub sib xyaw nrog txoj kev tshiab hauv tib lub luag haujlwm.
Thim kev sau npe thaum tus neeg siv tua cov ntawv ceeb toom
Khawm “Tua cov ntawv ceeb toom” yuav tsum ua ob yam tib si: hloov kho consent state ntawm server thiab rho tawm lossis lov tes taw qhov FCM registration uas cuam tshuam. Yog tsuas zais lub khawm hauv interface xwb, server tseem yuav xa tau ntawv ceeb toom rau token qub.
async function disableNotifications() {
const response = await fetch('/api/notification-subscription', {
method: 'DELETE',
headers: { 'Content-Type': 'application/json' },
credentials: 'include'
});
if (!response.ok) {
throw new Error(`Không thể tắt đăng ký: HTTP ${response.status}`);
}
showMessage('Đã tắt đăng ký thông báo trên tài khoản này.');
}
Cov code uas khiav hauv browser thiab /api/notification-subscription tsuas yog ib txoj kev piv txwv xwb; hloov nws ua koj lub app qhov API tiag. Server API yuav tsum txheeb xyuas tus neeg siv thiab tsuas lov tes taw qhov kev sau npe uas yog tus account ntawd li. Tsis txhob muab FCM server key, VAPID private key, lossis cov ntaub ntawv txheeb xyuas tus thawj tswj tso rau hauv JavaScript uas xa mus rau browser.
Tshawb xyuas cov ntsiab lus, cov txuas thiab qhov nquag xa ntawv ceeb toom

Txhua daim ntawv ceeb toom yuav tsum teb tau peb lo lus nug: Leej twg xa? Vim li cas kuv thiaj tau txais? Yog nias, nws yuav coj mus rau qhov twg? Yog tus neeg siv teb tsis tau peb lo lus nug no sai, daim ntawv ceeb toom yuav raug suav tias yog spam txawm tias txoj kev xa hauv tshuab ua haujlwm raug kawg.
- Npe: piav qhia ib qho xwm txheej kom meej, xws li “Koj qhov kev txiav txim tau xa txog lawm”; tsis txhob siv “Ceeb toom ceev” yog tsis muaj teeb meem tiag.
- Cov ntsiab lus: luv, raug thiab tsis tsim kev xav tias yuav poob ib yam dab tsi yam cuav lossis thov kom sau password yam tsis raug rau lub ntsiab lus.
- Icon: siv lub cim ntawm brand lossis khoom uas paub tau yooj yim; tsis txhob siv duab uas zoo li qhov kev ceeb toom ntawm operating system.
- Txuas: siv HTTPS, coj mus rau nplooj ntawv uas cuam tshuam ncaj qha thiab tsis txhob xa hla ntau lub domain uas tsis paub keeb kwm.
- Zaus xa: muab cov xwm txheej zoo sib xws sau ua ke, teeb ib qho kev txwv rau ib tus neeg siv thiab tso tseg kev xa thaum tsis muaj laj thawj tsim nyog lawm.
Rau cov web notification khiav tom qab, FCM pab txuas tus neeg siv rov qab mus rau hauv daim ntawv thov; qhov txuas no yuav tsum yog HTTPS URL. Cov ntaub ntawv Firebase kuj pom zoo kom lub npe qhia meej txog yam notification tiag tiag thiab tsis txhob rov sau lub npe website lossis domain rau hauv lub npe thaum browser twb qhia lub domain ntawd lawm (raws li firebase.google.com).
Tshawb xyuas Chrome Abusive Notifications Report
Yog koj yog tus tswv lossis yog tus neeg tau txais kev tso cai hauv Google Search Console, qhib Abusive Notifications Report ntawm koj lub domain. Daim ntawv tshaj tawm yuav qhia tau cov piv txwv ntawm nplooj ntawv, hom kev ua txhaum thiab txoj kev uas qhov kev paub ntawd tshwm sim. Daim ntawv tshaj tawm tsuas tshuaj xyuas ib qho qauv URL xwb, yog li kev kho ib nplooj ntawv xwb tsis txaus los xaus tias tag nrho lub domain muaj kev nyab xeeb lawm.
- Sau tseg URL, tus qauv ntawm interface thiab hom teeb meem uas muaj hauv daim ntawv tshaj tawm.
- Nrhiav qhov chaw uas tsim qhov kev paub ntawd: website tus code, tag manager, plugin, advertising network lossis library ntawm lwm tus.
- Tshem cov kev thov tso cai uas ua rau neeg to taub yuam kev thiab txhua yam notification cuav, dag ntxias lossis txuas mus rau software uas tsis xav tau.
- Tshawb xyuas cov template, landing page, subdomain thiab script uas siv sib koom.
- Tshawb xyuas dua siv browser profile tshiab thiab sim cov xwm txheej tso cai, tsis tso cai thiab rho qhov kev tso cai.
- Thaum kho tag nrho pawg teeb meem lawm, xa daim ntawv thov kom rov tshuaj xyuas.
Yog daim ntawv tshaj tawm qhia tias Failing, Chrome yuav thaiv tag nrho cov notification thiab txawm thaiv qhov kev thov tso cai ntawm lub website thiab. Google qhia tias daim ntawv tshaj tawm yog tsim los ntawm cov qauv URL, thiab yuav tsum kho ob qho kev ua txhaum uas tau teev tseg thiab cov kev ua txhaum zoo ib yam uas tseem tshuav; tom qab qhov xwm txheej hloov lawm, tej zaum yuav siv sijhawm ua ntej qhov kev hloov ntawd raug qhia kom tiav hauv Chrome (raws li support.google.com).
Tsob ntoo kuaj teeb meem ceev thaum tseem muaj web notification tsis tsim nyog
- Tsis pom lub qhov rai thov tso cai: kuaj lub domain qhov kev tso cai tam sim no, hom kev ceeb toom ntsiag to, HTTPS thiab browser txoj cai tswj hwm.
- Tus neeg siv twb tsis tso cai lawm tab sis tseem tau txais notification: nrhiav cov token qub, ntau lub domain lossis ntau lub service worker uas sau npe tib lub cuab yeej; muab cov ntaub ntawv ntawd lov tes taw ntawm server.
- Tsuas muaj qee tus neeg tau txais cov notification tsis raug: kuaj segment, topic, configuration cache thiab seb tus account uas tau logout puas rho nws qhov kev sau npe.
- Chrome rho qhov kev tso cai lossis thaiv qhov kev thov: kuaj Abusive Notifications Report, cov txheej interface cuav, cov script ntawm lwm tus thiab cov ntsiab lus ntawm cov txuas.
- Tau txais ntau daim uas zoo ib yam: kuaj seb puas muaj kev xa rov ua dua los ntawm notification message, data message thiab service worker tib si; xyuas kom tsuas muaj ib qho kev khiav haujlwm los qhia notification xwb.
- Rho service worker lawm tab sis tseem tau txais notification: kuaj lub domain permission, cov ntaub ntawv FCM ntawm server thiab lwm lub browser lossis subdomain; kev rho ib lub service worker tsis txhais tias yuav rho tus neeg siv txhua qhov kev tso cai nws tus kheej.
Daim ntawv txheeb xyuas ua ntej qhib rau coob tus neeg siv
- Thaum qhib nplooj ntawv thawj zaug, nws tsis hu qhov kev thov tso cai nws tus kheej.
- Cov lus piav qhia qhia meej tias yuav xa notification yam twg thiab xav tias yuav xa ntau npaum li cas.
- Tus neeg siv yeej hla tau qhov kev thov ntawd thiab tseem siv tau cov ntsiab lus tseem ceeb.
- FCM tsuas sau npe tom qab qhov xwm txheej ntawm permission yog
granted. - Token lossis Firebase Installation ID yuav tsum txuas rau tus neeg siv, domain thiab pawg ntsiab lus uas raug.
- Cov token uas yuam kev, qub lossis raug rho lawm yuav tsum muab lov tes taw ntawm server.
- Lub pob tua notification yuav hloov kho ob qho tib si: tus neeg siv qhov xwm txheej pom zoo thiab cov ntaub ntawv sau tseg rau kev xa.
- Notification yuav tsum tsis txhob ua txuj yog system alert, lus ntiag tug lossis kev ceeb toom txog kev nyab xeeb.
- Cov txuas hauv notification yuav tsum siv HTTPS thiab coj mus rau cov ntsiab lus uas raug.
- Tom qab tso rau siv lawm, twb tau kuaj Chrome Abusive Notifications Report.
Yog tab tom kho ib lub system qub, cia li siv txoj kev hloov pauv tsawg tshaj plaws: tua qhov kev thov tso cai uas khiav nws tus kheej → ntxiv lub pob sau npe kom meej → tso tseg kev xa mus rau cov token uas tsis tuaj yeem txheeb xyuas → rov tshuaj xyuas payload → kuaj Google daim ntawv tshaj tawm. Tom qab ntawd mam li kho kev faib pawg thiab kev xa ntau npaum li cas. Txoj kev no pab cais seb qhov yuam kev puas yog hais txog permission, cov ntaub ntawv sau npe lossis cov ntsiab lus, tsis yog hloov txhua yam tib lub sijhawm.
Cov ntaub ntawv siv
- Abusive notifications – Web Tools Help
- Introduction to the Abusive Notifications Report
- Chrome enforcement – Web Tools Help
- Manage Chrome safety and security – Computer
- Requests the notification permission on page load
- Get started with Firebase Cloud Messaging in Web apps
- Receive messages in Web apps

