Gloucestershire were frustrated by two wicketkeepers at opposite ends of the career spectrum on the third day of the LV=County Championship match against Essex at Bristol.
Having been dismissed for a wholly inadequate 134 in 43.1 overs in their first innings, the home side were well and truly in the hunt after reducing Essex to 71-5 on a pitch that was still doing enough to encourage the seam bowlers.
But veteran campaigner James Foster and young England wannabe Ben Foakes joined forces to alter the complexion of a hitherto low-scoring contest, staging a game-changing stand of 218 in 44 overs for the sixth wicket to put the visitors in control going into the final day.
Already 171 runs to the good after reaching the close on 305-8, Essex will be in a position to apply concerted pressure when they resume in pursuit of a second victory in three matches.
Still to win a game this season, Gloucestershire will have to find significant improvement with the bat on a pitch which is expected to flatten out if they are to stave off the threat of a second successive home defeat.
Unlike the home side, Essex bat all the way down and that superior strength in depth proved the deciding factor in a final session that yielded a staggering 190 runs.
An England wicketkeeper in the making, Foakes has been forced to play second fiddle to Foster with the gloves. In the team as a specialist batsman, the 21-year-old showed why he is so highly-rated, plundering an unbeaten career-best 132 from 157 balls, eclipsing the 120 he made against Leicestershire last season. He was especially severe on the bad ball, of which there were many, taking advantage of some mediocre bowling to accrue 14 fours as the runs flowed.
Elder statesman Foster was less prolific, yet still managed to harvest a valuable 91 from 121 balls before being caught at the wicket to hand Ian Saxelby a second wicket on his return to Championship action.
Of Gloucestershire's five-man seam attack, only Will Gidman and exerted any real control. Otherwise, much of the bowling was too short, lacking the pace to trouble the batsmen.
Foakes took full advantage, raising 50 from 88 balls before pressing the accelerator, going to his hundred from just 40 more deliveries. Dropped by Michael Klinger at mid-on off the bowling of James Fuller when he had scored 66, his innings was nevertheless remarkable in the context of what had gone before.
There were two wickets apiece for youngsters Graeme McCarter and Matt Taylor, while Saxelby marked his first Championship appearance since August 2012 with 3-71 from 19.5 overs.
Despite batting being somewhat easier than on day two, Essex contributed to their early problems in the form of some soft dismissals. This was especially true of England captain Alastair Cook, who was looking to add to hundreds scored in previous games against Derbyshire and Surrey.
He looked suitably chastened when he slapped the third ball after lunch, a rank long-hop from teenage rookie Taylor, straight to McCarter at point.
Fellow England star Bopara was equally culpable, offering a catch behind down the leg-side off McCarter, having contributed 14 runs in a fourth wicket stand of 41 with Jaik Mickelburgh.
Saxelby had already had Tom Westley held at first slip, confirming his return to fitness following an injury-enforced absence of 18 months.
Bopara's departure sparked a mini-collapse, McCarter locating Greg Smith's outside edge to afford Cameron Herring a regulation take and the hitherto exemplary Mickelburgh suffering a rush of blood and playing across the line to a straight ball from Taylor to depart lbw for 32.
Gloucestershire earlier resumed on 104-6 and lost their last four wickets for 30 runs in 12 overs.
The lower order simply had answer to David Masters, who adhered rigidly to the tenets of line and length to claim 6-48, in the process registering the 30th five-wicket haul of his career.
He was aided and abetted by Graham Napier, who claimed 4-62 from the Ashley Down Road end.
Only Chris Dent offered any kind of resistance and the Bristolian was last man out, caught at slip by Cook off Napier, having compiled a diligent 61 from 132 balls with 10 fours.