 
                 // Check the domain exceptions. If a domain exception matches, this filter does not apply.
                 for domainRegex in domainExceptions {
-                    let range = NSRange(location: 0, length: host.characters.count)
-                    if domainRegex.firstMatch(in: host, options: [], range: range) != nil {
+                    let range = NSRange(location: 0, length: documentHost.characters.count)
+                    if domainRegex.firstMatch(in: documentHost, options: [], range: range) != nil {
                         continue domainSearch
                     }
                 }

    }
}

private class BlockRule {
    fileprivate let regex: NSRegularExpression
    fileprivate let domainExceptions: [NSRegularExpression]?

    init(regex: NSRegularExpression, domainExceptions: [NSRegularExpression]?) {
        self.regex = regex
        self.domainExceptions = domainExceptions
    }
}

                    return try! NSRegularExpression(pattern: regex, options: [])
                }

                // "first-party" is not supported since we don't use it in any block lists.
                let loadTypes = trigger["load-type"] as? [String] ?? []
                let blockType = loadTypes.contains("third-party") ? BlockType.thirdParty : .all

                blockRules.append(BlockRule(regex: filterRegex, type: blockType, domainExceptions: domainExceptions))
            }
        }
    }

    func isBlocked(_ request: URLRequest) -> Bool {
        guard let documentUrl = request.mainDocumentURL,
              let documentHost = documentUrl.host,
            let resourceUrl = request.url else {
            return false
        }

        let resourceString = resourceUrl.absoluteString
        let resourceRange = NSRange(location: 0, length: resourceString.characters.count)
        let documentString = documentUrl.absoluteString
        let documentRange = NSRange(location: 0, length: documentString.characters.count)

        domainSearch: for rule in blockRules {
            // First, test the top-level filters to see if this URL might be blocked.
            if rule.regex.firstMatch(in: resourceString, options: .anchored, range: resourceRange) != nil {
                // If this is a third-party load, don't block first-party sites.
                if rule.type == .thirdParty {
                    if rule.regex.firstMatch(in: documentString, options: .anchored, range: documentRange) != nil {
                        continue
                    }
                }

                // We matched, and there are no exceptions.
                guard let domainExceptions = rule.domainExceptions else {
                    return true
