Skip to content

Commit ad32399

Browse files
committed
Add initiator_url to assets for analyze/collect tasks
1 parent fa821fe commit ad32399

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

engine/crawler.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ type Asset struct {
3737
ResourceType string `json:"resource_type"`
3838
RequestHeaders map[string]any `json:"request_headers"`
3939
ResponseHeaders map[string]any `json:"response_headers"`
40-
Body string `json:"body"`
40+
InitiatorURL string `json:"initiator_url,omitempty"`
41+
Body string `json:"body,omitempty"`
4142
}
4243

4344
func NewCrawler(userAgent string, winWidth, winHeight int64) Crawler {
@@ -83,6 +84,7 @@ func (c *Crawler) Visit(ctx context.Context, url string, logger *zerolog.Logger)
8384
URL: ev.Request.URL,
8485
ResourceType: string(ev.Type),
8586
RequestHeaders: ev.Request.Headers,
87+
InitiatorURL: ev.Initiator.URL,
8688
}
8789
}
8890

engine/crawler_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ func TestCrawlerVisit(t *testing.T) {
3939
assert.NotEmpty(t, scriptAsset.RequestHeaders)
4040
assert.NotEmpty(t, scriptAsset.ResponseHeaders)
4141
assert.NotEmpty(t, scriptAsset.Body)
42+
assert.NotEmpty(t, scriptAsset.InitiatorURL)
4243

4344
styleIdx := slices.IndexFunc(visit.Assets, matchAsset("style.css"))
4445
styleAsset := visit.Assets[styleIdx]
4546
assert.Equal(t, "Stylesheet", styleAsset.ResourceType)
4647
assert.NotEmpty(t, styleAsset.RequestHeaders)
4748
assert.NotEmpty(t, styleAsset.ResponseHeaders)
4849
assert.NotEmpty(t, styleAsset.Body)
50+
assert.NotEmpty(t, styleAsset.InitiatorURL)
4951
}
5052

5153
func TestCrawlerLastVisitWithoutAnyVisits(t *testing.T) {

0 commit comments

Comments
 (0)