Currently, when using query_domain() on a hosted feature layer you are returned and empty list (which is an improvement on previous versions where it caused an error)
It would be fantastic if this nice little function would work for hosted feature layers. I had reported as a bug but it seems this is by design, it is a function for enterprise services, why only enterprise? AGOL users need it too.
from arcgis import GIS
from arcgis.features import FeatureLayerCollection
## connect to agol
agol = GIS("home")
## get feature service as an item object
item = agol.content.get("FS_ITEM_ID")
## create a flc object from item object
flc = FeatureLayerCollection(item.url, agol)
## use the query_domains() method on the layer(s) of choice
domains = flc.query_domains(layers=[0])
print(domains)